1/*! 2 * ScrollMagic v2.0.6 (2018-10-08) 3 * The javascript library for magical scroll interactions. 4 * (c) 2018 Jan Paepke (@janpaepke) 5 * Project Website: http://scrollmagic.io 6 * 7 * @version 2.0.6 8 * @license Dual licensed under MIT license and GPL. 9 * @author Jan Paepke - [email protected] 10 * 11 * @file ScrollMagic GSAP Animation Plugin. 12 * 13 * requires: GSAP ~1.14 14 * Powered by the Greensock Animation Platform (GSAP): http://www.greensock.com/js 15 * Greensock License info at http://www.greensock.com/licensing/ 16 */ 17/** 18 * This plugin is meant to be used in conjunction with the Greensock Animation Plattform. 19 * It offers an easy API to trigger Tweens or synchronize them to the scrollbar movement. 20 * 21 * Both the `lite` and the `max` versions of the GSAP library are supported. 22 * The most basic requirement is `TweenLite`. 23 * 24 * To have access to this extension, please include `plugins/animation.gsap.js`. 25 * @requires {@link http://greensock.com/gsap|GSAP ~1.14.x} 26 * @mixin animation.GSAP 27 */ 28(function (root, factory) { 29 if (typeof define === 'function' && define.amd) { 30 // AMD. Register as an anonymous module. 31 define(['ScrollMagic', 'TweenMax', 'TimelineMax'], factory); 32 } else if (typeof exports === 'object') { 33 // CommonJS 34 // Loads whole gsap package onto global scope. 35 require('gsap'); 36 factory(require('scrollmagic'), TweenMax, TimelineMax); 37 } else { 38 // Browser globals 39 factory(root.ScrollMagic || (root.jQuery && root.jQuery.ScrollMagic), root.TweenMax || root.TweenLite, root.TimelineMax || root.TimelineLite); 40 } 41}(this, function (ScrollMagic, Tween, Timeline) { 42 "use strict"; 43 var NAMESPACE = "animation.gsap"; 44 45 var 46 console = window.console || {}, 47 err = Function.prototype.bind.call(console.error || console.log || 48 function () {}, console); 49 if (!ScrollMagic) { 50 err("(" + NAMESPACE + ") -> 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."); 51 } 52 if (!Tween) { 53 err("(" + NAMESPACE + ") -> ERROR: TweenLite or TweenMax could not be found. Please make sure GSAP is loaded before ScrollMagic or use an asynchronous loader like requirejs."); 54 } 55 56/* 57 * ---------------------------------------------------------------- 58 * Extensions for Scene 59 * ---------------------------------------------------------------- 60 */ 61 /** 62 * Every instance of ScrollMagic.Scene now accepts an additional option. 63 * See {@link ScrollMagic.Scene} for a complete list of the standard options. 64 * @memberof! animation.GSAP# 65 * @method new ScrollMagic.Scene(options) 66 * @example 67 * var scene = new ScrollMagic.Scene({tweenChanges: true}); 68 * 69 * @param {object} [options] - Options for the Scene. The options can be updated at any time. 70 * @param {boolean} [options.tweenChanges=false] - Tweens Animation to the progress target instead of setting it. 71 Does not affect animations where duration is `0`. 72 */ 73 /** 74 * **Get** or **Set** the tweenChanges option value. 75 * This only affects scenes with a duration. If `tweenChanges` is `true`, the progress update when scrolling will not be immediate, but instead the animation will smoothly animate to the target state. 76 * For a better understanding, try enabling and disabling this option in the [Scene Manipulation Example](../examples/basic/scene_manipulation.html). 77 * @memberof! animation.GSAP# 78 * @method Scene.tweenChanges 79 * 80 * @example 81 * // get the current tweenChanges option 82 * var tweenChanges = scene.tweenChanges(); 83 * 84 * // set new tweenChanges option 85 * scene.tweenChanges(true); 86 * 87 * @fires {@link Scene.change}, when used as setter 88 * @param {boolean} [newTweenChanges] - The new tweenChanges setting of the scene. 89 * @returns {boolean} `get` - Current tweenChanges option value. 90 * @returns {Scene} `set` - Parent object for chaining. 91 */ 92 // add option (TODO: DOC (private for dev)) 93 ScrollMagic.Scene.addOption("tweenChanges", // name 94 false, // default 95 96 97 function (val) { // validation callback 98 return !!val; 99 }); 100 // extend scene 101 ScrollMagic.Scene.extend(function () { 102 var Scene = this, 103 _tween; 104 105 var log = function () { 106 if (Scene._log) { // not available, when main source minified 107 Array.prototype.splice.call(arguments, 1, 0, "(" + NAMESPACE + ")", "->"); 108 Scene._log.apply(this, arguments); 109 } 110 }; 111 112 // set listeners 113 Scene.on("progress.plugin_gsap", function () { 114 updateTweenProgress(); 115 }); 116 Scene.on("destroy.plugin_gsap", function (e) { 117 Scene.removeTween(e.reset); 118 }); 119 120 /** 121 * Update the tween progress to current position. 122 * @private 123 */ 124 var updateTweenProgress = function () { 125 if (_tween) { 126 var 127 progress = Scene.progress(), 128 state = Scene.state(); 129 if (_tween.repeat && _tween.repeat() === -1) { 130 // infinite loop, so not in relation to progress 131 if (state === 'DURING' && _tween.paused()) { 132 _tween.play(); 133 } else if (state !== 'DURING' && !_tween.paused()) { 134 _tween.pause(); 135 } 136 } else if (progress != _tween.progress()) { // do we even need to update the progress? 137 // no infinite loop - so should we just play or go to a specific point in t
137ime? 138 if (Scene.duration() === 0) { 139 // play the animation 140 if (progress > 0) { // play from 0 to 1 141 _tween.play(); 142 } else { // play from 1 to 0 143 _tween.reverse(); 144 } 145 } else { 146 // go to a specific point in time 147 if (Scene.tweenChanges() && _tween.tweenTo) { 148 // go smooth 149 _tween.tweenTo(progress * _tween.duration()); 150 } else { 151 // just hard set it 152 _tween.progress(progress).pause(); 153 } 154 } 155 } 156 } 157 }; 158 159 /** 160 * Add a tween to the scene. 161 * If you want to add multiple tweens, add them into a GSAP Timeline object and supply it instead (see example below). 162 * 163 * If the scene has a duration, the tween's duration will be projected to the scroll distance of the scene, meaning its progress will be synced to scrollbar movement. 164 * For a scene with a duration of `0`, the tween will be triggered when scrolling forward past the scene's trigger position and reversed, when scrolling back. 165 * To gain better understanding, check out the [Simple Tweening example](../examples/basic/simple_tweening.html). 166 * 167 * Instead of supplying a tween this method can also be used as a shorthand for `TweenMax.to()` (see example below). 168 * @memberof! animation.GSAP# 169 * 170 * @example 171 * // add a single tween directly 172 * scene.setTween(TweenMax.to("obj"), 1, {x: 100}); 173 * 174 * // add a single tween via variable 175 * var tween = TweenMax.to("obj"), 1, {x: 100}; 176 * scene.setTween(tween); 177 * 178 * // add multiple tweens, wrapped in a timeline. 179 * var timeline = new TimelineMax(); 180 * var tween1 = TweenMax.from("obj1", 1, {x: 100}); 181 * var tween2 = TweenMax.to("obj2", 1, {y: 100}); 182 * timeline 183 * .add(tween1) 184 * .add(tween2); 185 * scene.addTween(timeline); 186 * 187 * // short hand to add a TweenMax.to() tween 188 * scene.setTween("obj3", 0.5, {y: 100}); 189 * 190 * // short hand to add a TweenMax.to() tween for 1 second 191 * // this is useful, when the scene has a duration and the tween duration isn't important anyway 192 * scene.setTween("obj3", {y: 100}); 193 * 194 * @param {(object|string)} TweenObject - A TweenMax, TweenLite, TimelineMax or TimelineLite object that should be animated in the scene. Can also be a Dom Element or Selector, when using direct tween definition (see examples). 195 * @param {(number|object)} duration - A duration for the tween, or tween parameters. If an object containing parameters are supplied, a default duration of 1 will be used. 196 * @param {object} params - The parameters for the tween 197 * @returns {Scene} Parent object for chaining. 198 */ 199 Scene.setTween = function (TweenObject, duration, params) { 200 var newTween; 201 if (arguments.length > 1) { 202 if (arguments.length < 3) { 203 params = duration; 204 duration = 1; 205 } 206 TweenObject = Tween.to(TweenObject, duration, params); 207 } 208 try { 209 // wrap Tween into a Timeline Object if available to include delay and repeats in the duration and standardize methods. 210 if (Timeline) { 211 newTween = new Timeline({ 212 smoothChildTiming: true 213 }).add(TweenObject); 214 } else { 215 newTween = TweenObject; 216 } 217 newTween.pause(); 218 } catch (e) { 219 log(1, "ERROR calling method 'setTween()': Supplied argument is not a valid TweenObject"); 220 return Scene; 221 } 222 if (_tween) { // kill old tween? 223 Scene.removeTween(); 224 } 225 _tween = newTween; 226 227 // some properties need to be transferred it to the wrapper, otherwise they would get lost. 228 if (TweenObject.repeat && TweenObject.repeat() === -1) { // TweenMax or TimelineMax Object? 229 _tween.repeat(-1); 230 _tween.yoyo(TweenObject.yoyo()); 231 } 232 // Some tween validations and debugging helpers 233 if (Scene.tweenChanges() && !_tween.tweenTo) { 234 log(2, "WARNING: tweenChanges will only work if the TimelineMax object is available for ScrollMagic."); 235 } 236 237 // check if there are position tweens defined for the trigger and warn about it :) 238 if (_tween && Scene.controller() && Scene.triggerElement() && Scene.loglevel() >= 2) { // controller is needed to know scroll direction. 239 var 240 triggerTweens = Tween.getTweensOf(Scene.triggerElement()),
241 vertical = Scene.controller().info("vertical"); 242 triggerTweens.forEach(function (value, index) { 243 var 244 tweenvars = value.vars.css || value.vars, 245 condition = vertical ? (tweenvars.top !== undefined || tweenvars.bottom !== undefined) : (tweenvars.left !== undefined || tweenvars.right !== undefined); 246 if (condition) { 247 log(2, "WARNING: Tweening the position of the trigger element affects the scene timing and should be avoided!"); 248 return false; 249 } 250 }); 251 } 252 253 // warn about tween overwrites, when an element is tweened multiple times 254 if (parseFloat(TweenLite.version) >= 1.14) { // onOverwrite only present since GSAP v1.14.0 255 var 256 list = _tween.getChildren ? _tween.getChildren(true, true, false) : [_tween], 257 // get all nested tween objects 258 newCallback = function () { 259 log(2, "WARNING: tween was overwritten by another. To learn how to avoid this issue see here: https://github.com/janpaepke/ScrollMagic/wiki/WARNING:-tween-was-overwritten-by-another"); 260 }; 261 for (var i = 0, thisTween, oldCallback; i < list.length; i++) { /*jshint loopfunc: true */ 262 thisTween = list[i]; 263 if (oldCallback !== newCallback) { // if tweens is added more than once 264 oldCallback = thisTween.vars.onOverwrite; 265 thisTween.vars.onOverwrite = function () { 266 if (oldCallback) { 267 oldCallback.apply(this, arguments); 268 } 269 newCallback.apply(this, arguments); 270 }; 271 } 272 } 273 } 274 log(3, "added tween"); 275 276 updateTweenProgress(); 277 return Scene; 278 }; 279 280 /** 281 * Remove the tween from the scene. 282 * This will terminate the control of the Scene over the tween. 283 * 284 * Using the reset option you can decide if the tween should remain in the current state or be rewound to set the target elements back to the state they were in before the tween was added to the scene. 285 * @memberof! animation.GSAP# 286 * 287 * @example 288 * // remove the tween from the scene without resetting it 289 * scene.removeTween(); 290 * 291 * // remove the tween from the scene and reset it to initial position 292 * scene.removeTween(true); 293 * 294 * @param {boolean} [reset=false] - If `true` the tween will be reset to its initial values. 295 * @returns {Scene} Parent object for chaining. 296 */ 297 Scene.removeTween = function (reset) { 298 if (_tween) { 299 if (reset) { 300 _tween.progress(0).pause(); 301 } 302 _tween.kill(); 303 _tween = undefined; 304 log(3, "removed tween (reset: " + (reset ? "true" : "false") + ")"); 305 } 306 return Scene; 307 }; 308 309 }); 310}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.