Git Product home page Git Product logo

scrollxp's Introduction

ScrollXP

ScrollXP is a library that makes it easy to drop scroll-related animations into your website using HTML data attributes. It's a bit like Alpine.js or Tailwind.css ... but for animations.

Overview

Creating animations can be tedious. It's not always clear where the code should go and there are a number of common animations you'll likely write over and over again. If you're not careful you JavaScript files can end up a mess. ScrollXP helps you avoid this by exposing a set of data attributes that you can drop directly into your HTML, making common animations quick and easy.

Demos

See some simple examples in action:

Installation

Via NPM:

$ npm install gsap scrollxp --save

Note: You need to use GSAP 3 or greater.

Include it in your script:

import ScrollXP from "scrollxp"

Or via CDN:

<script src="https://unpkg.com/gsap/dist/gsap.min.js"></script>
<script src="https://unpkg.com/scrollxp/dist/scrollxp.min.js"></script>

Quick Start

new ScrollXP({
  container: document.body,
})

ScrollXP uses GSAP (GreenSock) and ScrollMagic under-the-hood.

ScrollXP relies on the concept of "scenes" from ScrollMagic. A scene is a section of page that will act as a container or scope for particular animations. You define these scenes by adding the data-scene attribute to elements. You then add the animations you want to perform within the scene.

Check the documentation about how to create scenes, animations and parallax effect.

Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/gsap/dist/gsap.min.js"></script>
    <script src="https://unpkg.com/scrollxp/dist/scrollxp.min.js"></script>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        display: flex;
        align-items: center;
        height: 200vh;
      }

      section {
        width: 100%;
        height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      section>div {
        width: 300px;
        height: 300px;
        border: 10px solid #000;
      }
    </style>
  </head>
  <body>
    <section data-scene data-scene-duration="100%" data-scene-indicator="scene">
      <div data-animate data-animate-to-rotation="360"></div>
    </section>
    <script>
      new ScrollXP({
        container: document.body,
      });
    </script>
  </body>
</html>

Usage

Check out our documentation for more detailed configuration and usage:

Questions?

File a GitHub issue please.

Author

Feral

License

ScrollXP is available under the MIT license. See the LICENSE file for more info.

scrollxp's People

Contributors

dependabot[bot] avatar thiagorossener avatar timmyomahony avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scrollxp's Issues

Demos aren't working

It looks like the demos aren't working anymore. There are javascript errors preventing them from running.

Load smooth-scrollbar dynamically

Currently, the smooth-scrollbar is automatically added to the bundle even if it's not being used.

The idea is making it work as a plugin.

Function to finish all animations at bottom of page

I've noticed that animations wont finish on some larger screens due to the scroll never getting to the data-scene-trigger where it's triggering the animation. A fallback to finish these remaining animations at the end of the container would be a nice feature πŸ‘Œ

(I wasn't able to find any functionality like this one in the docs)

Add wrapper when using smooth scrolling

ScrollMagic doesn't need a wrapper to work, it works fine in the <body>. However, documentation is saying a wrapper is required.

TO DO:

  • Create wrapper dynamically if the container is the <body> and smooth scrolling is on
  • Remove wrapper if smooth scrolling is off
  • Improve documentation

Improve first load documentation

Add into the documentation how to avoid blinking components when JS is still loading.

Basically, we need to guarantee the components are invisible until the library is about to initialize.

A .is-loading [data-animate] { visibility: hidden; } should sort it out.

Parallax not smooth on mobile devices

Hello, thank you for developing ScrollXP!

I want to create a parallax effect for a few (<10) elements like

<div class="parallax"
    data-animate
    data-animate-from-y="100"
    data-animate-to-y="-100">

but unfortunately it is not really smooth. On desktop (M1) it animates almost smooth, but on a smartphone (iPhone 13) it flickers and stutters a bit, on iPhone X so heavily that the page feels broken.
I don’t use any other animations and transitions that could interfere.

What am I doing wrong? Is there a piece I am missing?
Thank you for any advice!

Anchors stop working on turn on/off smooth scrolling

  • Go to the demo page
  • Turn smooth scrolling on
  • Turn smooth scrolling off
  • Click on a menu item

Error:

ScrollToPlugin.js:51 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null
    at l (ScrollToPlugin.js:51)
    at r (ScrollToPlugin.js:75)
    at Object.init [as _onInitTween] (ScrollToPlugin.js:110)
    at v.r._initProps (TweenMax.js:7559)
    at v.r._init (TweenMax.js:7519)
    at v.t.render (TweenMax.js:302)
    at Object.r.render (TweenMax.js:7026)
    at Object.M._updateRoot.L.render (TweenMax.js:7301)
    at Object.r.dispatchEvent (TweenMax.js:6436)
    at r (TweenMax.js:6488)

Consider upgrade to GSAP 3

GSAP recently released v3 that is simpler and lighter. However, I'm not sure that ScrollMagic has updated to fully work with this new version.

TO DO:

  • Investigate and check if it's a good change
  • If so, upgrade to GSAP 3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.