├── animation.anime.min.js
├── README.md
├── LICENSE
└── animation.anime.js
/animation.anime.min.js:
--------------------------------------------------------------------------------
1 | !function(e,n){"function"==typeof define&&define.amd?define(["ScrollMagic","animejs"],n):"object"==typeof exports||n(e.ScrollMagic||e.jQuery&&e.jQuery.ScrollMagic,e.anime||e.jQuery&&e.jQuery.anime)}(this,function(e,n){"use strict";var i=0;e.Scene.extend(function(){var n,r=this,o=(e._util,0);r.on("progress.plugin_anime",function(){t()}),r.on("destroy.plugin_anime",function(e){r.off("*.plugin_anime"),r.removeAnime(e.reset)});var t=function(){if(n){var e=r.progress();e!=o&&(0===r.duration()?e>0?n.play():((i=n).play(),i.reverse()):n.seek(n.duration*e),o=e)}var i};r.setAnime=function(e){return n&&r.removeAnime(),e.pause(),n=e,"ScrollMagic.animation.anime["+i+++"]",t(),r},r.removeAnime=function(e){return n&&(e&&n.seek(0).pause(),n=void 0),r}})});
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # scrollanime
2 | ScrollMagic plugin for AnimeJS Animation Engine.
3 |
4 | ## Installation
5 |
6 | Download `animation.anime.min.js` and include it after ScrollMagic and Anime.
7 | ```html
8 |
9 |
10 |
11 | ```
12 |
13 | ## Usage
14 |
15 | ```javascript
16 | var tl = anime.timeline();
17 | tl.add({
18 | targets: "#block",
19 | opacity: [0, 1]
20 | }).add({
21 | targets: "#block-1",
22 | opacity: [0, 1]
23 | });
24 |
25 | var animation = anime({
26 | targets: ".blocks",
27 | scale: [0.5, 1]
28 | });
29 |
30 | new ScrollMagic.Scene({
31 | triggerElement: ".section",
32 | duration: "80%",
33 | triggerHook: 0.9
34 | })
35 | .setAnime(tl)
36 | .addTo(controller);
37 |
38 | new ScrollMagic.Scene({
39 | triggerElement: ".section-2",
40 | duration: "80%",
41 | triggerHook: 0.9
42 | })
43 | .setAnime(animation)
44 | .addTo(controller);
45 | ```
46 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Andrew Developer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/animation.anime.js:
--------------------------------------------------------------------------------
1 | /*
2 | AnimeJS plugin for ScrollMagic.
3 | Powered by AnimeJS: http://animejs.com.
4 | AnimeJS is published under MIT license.
5 | */
6 | (function(root, factory) {
7 | if (typeof define === "function" && define.amd) {
8 | // AMD
9 | define(["ScrollMagic", "animejs"], factory);
10 | } else if (typeof exports === "object") {
11 | // CommonJS is not supporter by AnimeJS
12 | } else {
13 | // Browser
14 | factory(
15 | root.ScrollMagic || (root.jQuery && root.jQuery.ScrollMagic),
16 | root.anime || (root.jQuery && root.jQuery.anime)
17 | );
18 | }
19 | })(this, function(ScrollMagic, anime) {
20 | "use strict";
21 | var NAMESPACE = "animation.anime";
22 |
23 | // (BUILD) - REMOVE IN MINIFY - START
24 | var console = window.console || {},
25 | err = Function.prototype.bind.call(
26 | console.error || console.log || function() {},
27 | console
28 | );
29 | if (!ScrollMagic) {
30 | err(
31 | "(" +
32 | NAMESPACE +
33 | ") -> ERROR: The ScrollMagic main module could not be found. Please make sure it's loaded before this plugin or use an asynchronous loader like requirejs."
34 | );
35 | }
36 | if (!anime) {
37 | err(
38 | "(" +
39 | NAMESPACE +
40 | ") -> ERROR: AnimeJS could not be found. Please make sure it's loaded before ScrollMagic or use an asynchronous loader like requirejs."
41 | );
42 | }
43 | // (BUILD) - REMOVE IN MINIFY - END
44 |
45 | var autoindex = 0;
46 |
47 | ScrollMagic.Scene.extend(function() {
48 | var Scene = this,
49 | _util = ScrollMagic._util,
50 | _currentProgress = 0,
51 | _animation,
52 | _dataID;
53 |
54 | // (BUILD) - REMOVE IN MINIFY - START
55 | var log = function() {
56 | if (Scene._log) {
57 | // not available, when main source minified
58 | Array.prototype.splice.call(
59 | arguments,
60 | 1,
61 | 0,
62 | "(" + NAMESPACE + ")",
63 | "->"
64 | );
65 | Scene._log.apply(this, arguments);
66 | }
67 | };
68 | // (BUILD) - REMOVE IN MINIFY - END
69 |
70 | // set listeners
71 | Scene.on("progress.plugin_anime", function() {
72 | updateAnimationProgress();
73 | });
74 | Scene.on("destroy.plugin_anime", function(e) {
75 | Scene.off("*.plugin_anime");
76 | Scene.removeAnime(e.reset);
77 | });
78 |
79 | var animate = function(animation) {
80 | animation.play();
81 | };
82 | var reverse = function(animation) {
83 | animation.play();
84 | animation.reverse();
85 | };
86 |
87 | /**
88 | * Seek animation while scrolling
89 | * @private
90 | */
91 | var updateAnimationProgress = function() {
92 | if (_animation) {
93 | var progress = Scene.progress();
94 | if (progress != _currentProgress) {
95 | // Need to update progress?
96 | if (Scene.duration() === 0) {
97 | // Play animation
98 | if (progress > 0) {
99 | // Play Forward
100 | animate(_animation);
101 | } else {
102 | // Play Reverse
103 | reverse(_animation);
104 | }
105 | } else {
106 | _animation.seek(_animation.duration * progress);
107 | }
108 | _currentProgress = progress;
109 | }
110 | }
111 | };
112 | Scene.setAnime = function(animation) {
113 | if (_animation) {
114 | // Kill old instance
115 | Scene.removeAnime();
116 | }
117 | animation.pause();
118 | _animation = animation;
119 | _dataID = "ScrollMagic." + NAMESPACE + "[" + autoindex++ + "]";
120 |
121 | updateAnimationProgress();
122 | return Scene;
123 | };
124 | Scene.removeAnime = function(reset) {
125 | if (_animation) {
126 | if (reset) {
127 | _animation.seek(0).pause();
128 | }
129 | _animation = undefined;
130 | }
131 | return Scene;
132 | };
133 | });
134 | });
135 |
--------------------------------------------------------------------------------