Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

scrollmagic

janpaepke113.5k(MIT OR GPL-3.0+)2.0.8TypeScript support: definitely-typed

The javascript library for magical scroll interactions.

scroll, scrolling, animation, sticky, pin, fixed, scrollbar, scrub, sync, position, progress, parallax, events, classes, jquery-plugin, ecosystem:jquery, scroll, scrolling, animation, sticky, pin, fixed, scrollbar, scrub, sync, position, progress, parallax, events, classes, jquery-plugin, ecosystem:jquery, scroll, scrolling, animation, sticky, pin, fixed, scrollbar, scrub, sync, position, progress, parallax, events, classes, jquery-plugin, ecosystem:jquery, scroll, scrolling, animation, sticky, pin, fixed, scrollbar, scrub, sync, position, progress, parallax, events, classes, jquery-plugin, ecosystem:jquery, scroll, scrolling, animation, sticky, pin, fixed, scrollbar, scrub, sync, position, progress, parallax, events, classes, jquery-plugin, ecosystem:jquery

readme

ScrollMagic v2.0.8 Build Status

The javascript library for magical scroll interactions.

Donate Request personal live support

Quicklinks: About | Download | Installation | Usage | Help | Compatibility | Author | License | Thanks


ScrollMagic helps you to easily react to the user's current scroll position.
It's the perfect library for you, if you want to ...

  • animate based on scroll position – either trigger an animation or synchronize it to the scrollbar movement (like a playback scrub control).
  • pin an element starting at a specific scroll position – either indefinitely or for a limited amount of scroll progress (sticky elements).
  • toggle CSS classes of elements on and off based on scroll position.
  • effortlessly add parallax effects to your website.
  • create an infinitely scrolling page (ajax load of additional content).
  • add callbacks at specific scroll positions or while scrolling past a specific section, passing a progress parameter.

Check out the demo page, browse the examples or read the documentation to get started.
If you want to contribute please get in touch and let me know about your specialty and experience.

About the Library

ScrollMagic is a scroll interaction library.

It's a complete rewrite of its predecessor Superscrollorama by John Polacek.
A plugin-based architecture offers easy customizability and extendability.

To implement animations, ScrollMagic can work with multiple frameworks. The recommended solution is the Greensock Animation Platform (GSAP) due to its stability and feature richness. For a more lightweight approach the VelocityJS framework is also supported. Alternatively custom extensions can be implemented or the necessity of a framework can be completely avoided by animating simply using CSS and class toggles.

ScrollMagic was developed with these principles in mind:

  • optimized performance
  • lightweight (6KB gzipped)
  • flexibility and extendibility
  • mobile compatibility
  • event management
  • support for responsive web design
  • object oriented programming and object chaining
  • readable, centralized code and intuitive development
  • support for both x and y direction scrolling (even both on one page)
  • support for scrolling inside div containers (even multiple on one page)
  • extensive debugging and logging capabilities
  • detailed documentation
  • many application examples

Is ScrollMagic the right library for you?
ScrollMagic takes an object oriented approach using a controller for each scroll container and attaching multiple scenes defining what should happen at what part of the page. While this offers a great deal of control, it might be a little confusing, especially if you're just starting out with javascript.
If the above points are not crucial for you and you are just looking for a simple solution to implement css animations I would strongly recommend taking a look at the awesome skrollr project. It almost solely relies on element attributes and thus requires minimal to no javascript knowledge.

Availability

To get your copy of ScrollMagic you have the choice between four options:

Option 1: GitHub
Download a zip file containing the source code, demo page, all examples and documentation from the GitHub releases page or clone the package to your machine using the git command line interface:

git clone https://github.com/janpaepke/ScrollMagic.git

Option 2: Bower
ScrollMagic is also available on bower and will only install the necessary source code, ignoring all example and documentation files.
Please mind that since they are not core dependencies, you will have to add frameworks like GSAP, jQuery or Velocity manually, should you choose to use them.

bower install scrollmagic

Option 3: npm
If you prefer the node package manager, feel free to use it.
Keep in mind that like with bower non-crucial files will be ignored (see above).

npm install scrollmagic

Option 4: CDN
If you don't want to host ScrollMagic yourself, you can include it from cdnjs:

https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.8/ScrollMagic.min.js

All plugins and uncompressed files are also available on cdnjs.
For example:

https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.8/plugins/debug.addIndicators.js
https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.8/plugins/debug.addIndicators.min.js

Installation

Include the core library in your HTML file:

<script src="js/scrollmagic/uncompressed/ScrollMagic.js"></script>

And you're ready to go!
For deployment use the minified version instead:

<script src="js/scrollmagic/minified/ScrollMagic.min.js"></script>

NOTE: The logging feature is removed in the minified version due to file size considerations.

To use plugins like the indicators visualization, simply include them additionally to the main library:

<script src="js/scrollmagic/uncompressed/plugins/debug.addIndicators.js"></script>

To learn how to configure RequireJS, when using AMD, please read here.

Usage

The basic ScrollMagic design pattern is one controller, which has one or more scenes attached to it.
Each scene is used to define what happens when the container is scrolled to a specific offset.

Here's a basic workflow example:

// init controller
var controller = new ScrollMagic.Controller();

// create a scene
new ScrollMagic.Scene({
    duration: 100, // the scene should last for a scroll distance of 100px
    offset: 50 // start this scene after scrolling for 50px
})
    .setPin('#my-sticky-element') // pins the element for the the scene's duration
    .addTo(controller); // assign the scene to the controller

To learn more about the ScrollMagic code structure, please read here.

Help

To get started, check out the available learning resources in the wiki section.
Be sure to have a look at the examples to get source code pointers and make use of the documentation for a complete reference.

If you run into trouble using ScrollMagic please follow the Troubleshooting guide.

Please do not post support requests in the github issue section, as it's reserverd for issue and bug reporting. If all above options for self-help fail, please use Stack Overflow or the ScrollMagic Premium Support.

Browser Support

ScrollMagic aims to support all major browsers even in older versions:
Firefox 26+, Chrome 30+, Safari 5.1+, Opera 10+, IE 9+

About the Author

I am a creative coder based in Vienna, Austria.

Learn more on my website or Follow me on Twitter

License

ScrollMagic is dual licensed under the MIT license and GPL.
For more information click here.

Thanks

This library was made possible by many people who have supported it with passion, donations or advice. Special thanks go out to: John Polacek, Jack Doyle, Paul Irish, Nicholas Cerminara, Kai Dorschner, Petr Tichy and Dennis Gaebel.

changelog

CHANGELOG

2.0.7 (2019-05-07)

bugfixes:

  • error in Safari when using setPin PR 382
  • added missing semi-colon to isMobile regex PR 617
  • fixed SVG element detection as Dom Element and related Error on Safari PR 447
  • fixed code selection in examples

changes (non-breaking):

  • pass Scene as this to duration callback PR 419
  • increase fps limit for mobile support(advance) example. PR 753
  • added documentation for responsive duration (e.g. "100%")
  • updated Section Wipes (natural) to work for large number of sections.
  • removed warning for pushFollowers in pins with duration 0, unless actively set to true
  • fixed some spelling stuff

new examples:

project management:

  • updated: build routine for gulp 4
  • updated: all Dependencies
  • changed: folder structure for a tidier root
  • fixed: unit test errors
  • added: Buttons for ScrollMagic Premium Support.

2.0.6 (2018-10-08)

bugfixes:

  • errors occurred, when removing a triggerElement see here
  • semantic error in removePin()

2.0.5 (2015-04-29)

bugfixes:

  • a JS error occurred in IE9 see here
  • cascading pins of absolutely positioned elements didn't work see here
  • scene state wasn't correct at start position see here
  • updatePinState was called before scrollOffset update see here

2.0.3 (2015-04-07)

changes (non-breaking)

  • moved to new jQuery plugin definition via npm see here
  • updated and improved several examples
  • optimized minification
  • changed command line options for build (version bumping)

bugfixes:

  • height calculation for pinned elements when using pushFollowers: false was faulty
  • parallax jitter fix for chrome
  • when using responsive duration and pushFollowers = true, an invalid console warning message was triggered
  • the sourcecode viewer in the examples code was showing modified code
  • fixed a problem when using the mousewheel to scroll over fixed elements after replacing the default scroll method of the controller
  • using pinned elements as Controller.scrollTo() targets didn't work properly
  • mousewheel over pinned elements inside of div scroll containers didn't work in IE

features

  • it's now possible to supply additional parameters to custom scrollTo functions see here

new examples:

2.0.2 (2015-03-23)

bugfixes:

  • Size calculations for pinned elements were off in certain conditions see here
  • scrollDirection detection broke in 2.0.1 see here

2.0.1 (2015-03-17)

features

  • better npm/browserify support see here

bugfixes:

  • missing browser global when using jQuery plugin see here
  • resolving jitters due to out-of-sync scroll positions see here

2.0.0 (2015-02-26)

changes (non-breaking)

  • removal of all dependencies (jQuery & GSAP) – ScrollMagic is now stand-alone.
  • new file structure:
    • main module: 'ScrollMagic.js'
    • all available plugins in folder '/plugins'
  • new scene event: add fires when scene is added to a controller
  • new scene event: remove fires when scene is removed from a controller
  • option changes in Scene.addIndicators():
    • indicators are now always on top (option zindex removed)
    • option suffix is renamed to name
  • several performance tweaks
  • lots more info and warning messages (in the uncompressed development version)

changes (potentially breaking):

  • ScrollMagic Controllers are now instantiated using var controller = new ScrollMagic.Controller();
  • ScrollMagic Scenes are now instantiated using var scene = new ScrollMagic.Scene();
  • renamed method Scene.parent() to Scene.controller()
  • removed scene method triggerOffset()
    Method was marked deprecated since v1.1.0 and has now been replaced by triggerPosition().
  • removed Scene.setPin() option pinClass
    Was used to add a class to the pinned element. The same can now be achieved using setClassToggle().

features:

  • new plugin 'debug.addIndicators' (formerly 'jquery.scrollmagic.debug')
    • indicators can now be added to the scene before it was added to a controller
    • indicators also work when scenes are removed and readded
    • indicator labels are autoindexed, when no explicit label is supplied
    • new controller option 'addIndicators', when a controller is initialized using new ScrollMagic.Controller({addIndicators: true}) all added scenes will automatically have indicators added to them
    • start indicator is now above the line for less overlays (i.e. one scene starts, where another ends)
    • huge performance optimization, especially when using indicators for multiple scenes
    • new method removeIndicators()
  • new plugin 'animation.gsap'
    • Contains all GSAP tween functionality formerly integrated into ScrollMagic (setTween() and removeTween())
    • new feature for shorthand TweenMax.to() animation using setTween(target, duration, parameters) or setTween(target, parameters)
  • new plugin 'animation.velocity'
    The velocity animation framework can now be used to trigger animations using Scene.setVelocity(target, properties, options) Note that for the time being velocity only works with 0 duration scenes, because timeline scrubbing isnt supported by velocity (yet).
  • new plugin 'jquery.ScrollMagic'
    • adds support for jQuery selectors and makes all methods accept jQuery objects as element parameters.
    • moves ScrollMagic global to $.ScrollMagic. To instantiate a controller respectively call new $.ScrollMagic.Controller().
  • new option for responsive duration The Scene duration can now be a percentage string like "100%".
    It will be calculated in relation to the size of the scroll container. It use the container's height for vertically scrolling applications and its width for horizontally scrolling containers.

bugfixes:

  • vertical Pins in DIV scroll containers did not work, when using a mousewheel while the cursor was over the pinned element
  • using removeTween(true) to remove and reset a Tween didn't work when the scene's duration was 0
  • when removing pins from cascaded pins using removePin(true) messed up the DOM structure (long term bug)
  • when pinning absolutely positioned elements using bottom or right, the positioning was off (See issue 226)

project management:

  • changed build system to gulp see here
  • moved all Module dist files to '/scrollmagic' see here
  • published scrollmagic on npm as scrollmagic
  • renamed package on bower from ScrollMagic to scrollmagic to adhere to naming conventions

1.3.0 (2014-11-13)

changes (potentially breaking):

  • changed AMD loader behavior to export only one object -> {Controller: ScrollMagic, Scene: ScrollScene}

bugfixes:

  • added Error message for missing dependencies
  • fixed bubbling of pseudo-resize event of div containers
  • reference bug with AMD loading

1.2.0 (2014-10-14)

features

  • AMD loader support (See issue 160)
  • added warning for tweens being overwritten (See issue 145)

changes (non-breaking):

  • better code for mobile clicks (See issue 169)
  • updated draw example to camel case to support Firefox
  • updated parralax sections example to moving divs instead of background position
  • added new references
  • added favicon

bugfixes:

  • scroll momentum increased in Firefox over fixed elements (See issue 164)
  • parallax example was juggy in Firefox and Safari -> removed reliance of TweenMax ticker in favor of requestAnimationFrame (See issue 167)
  • bugfix for pinned elements jittering if inside a container, because of the delayed position update in refreshInterval

1.1.0 (2014-09-04)

changes (potentially breaking):

  • zero duration scene events & states
    The event logic for zero duration scenes has been changed: From now on a zero duration scene will trigger enter, start, progress (in this order) when scrolling forward past the trigger point and progress, start, leave when scrolling in reverse.
    This means there will never be an end event triggered, which reflects the behaviour more accurately.
    Furthemore this affects the scene's possible states, which can now only be "BEFORE" and "DURING" for zero duration scenes.
    To learn more, read this issue or this documentation.
  • removed method startPosition()
    Method was marked deprecated since v1.0.7 and has now been replaced by triggerPosition().
    The terms "offset" and "position" were used too randomly.
    To avoid confision, from now on "offset" will be used in connection with the scroll offset of the container, while "position" refers to the top / left values within the DOM.
  • change event only fires when change actually happened
    If a setter is used with the current value or the internal validator fails and defaults to the same value an option is already set to, no change event will be fired anymore.

changes (non-breaking)

  • scenes are sorted in controller
    Scenes attached to the same controller are now updated in the order of their start position.
    This way DOM modifcations (e.g. tweens) that influence each other are sure to be called in the right order.
    To learn more, read this issue.
  • marked triggerOffset as deprecated, replaced by triggerPosition
    Renaming to avoid confusion. Read above for clarification.
  • new controller option refreshInterval
    To update values that otherwise wouldn't fire an event a refreshInterval option was added to poll for changes.
    These changes involve resizing of a div scroll container or movement of a scene's trigger element position.
  • no more logging in minified version
    All debug logging functionality was removed when using the minified version to save on filesize.

features:

  • new controller method: scrollTo
  • new controller method: scrollPos
  • new scene method: refresh
  • new scene method: setClassToggle, removeClassToggle respectively
  • new scene event: shift fires when scene position changes
  • new scene event: destroy fires when scene is destroyed
  • extended scene option duration to support dynamic updates in responsive layouts
  • docs: grouped methods for more clear arrangement
  • docs: various additions and clarifications

bugfixes:

  • removing and resetting pins during pin phase didn't work properly
  • using mousewheel to scroll over pinned elements in container (See issues 34, 50, 82, 139, 140)
  • pin width collapsed, if no width was defined (See issues 63, 94)
  • positioned pins didn't work in IE 9
  • padding of pinned elements was added to relative width
  • event namespace issues
  • docs: fixed highlight & deeplink issues

new examples: