You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using ScrollMagic with React and webpack. Tricky configurations are needed to get the code compiled with webpack but I think the main problem lies in the source code itself.
Issue
I appreciate all the efforts made by the development team to accommodate different versions of gsap in animation.gsap.js. Since the latest version of gsap wraps TweenMax, TimelineMax, TweenLite, TimelineLite, etc. into the gsap object, the current version of animation.gsap.js doesn't work with the lastest gsap@^3.5.1.
All the following code snippets are taken fromscrollmagic/uncompressed/plugins/animation.gsap.js.
The error is related to the function Scene.setTween. The following is the error message shown in the console when setTween is called:
TypeError: Tween.to is not a function (animation.gsap.js: 255)
Backtracking where the variable Tween is initialized, I found the following chunk of code which caused the problem:
(function(root,factory){if(typeofdefine==='function'&&define.amd){// AMD. Register as an anonymous module.define(['ScrollMagic','gsap','TweenMax','TimelineMax'],factory);}elseif(typeofexports==='object'){// CommonJS// Loads whole gsap package onto global scope.vargsap=require("gsap/dist/gsap")||require("gsap");// TweenMax/TimelineMax will be global in v2. In v3, they will be on the gsap objectfactory(require('scrollmagic'),gsap,TweenMax||gsap,TimelineMax||gsap);}else{// Browser globalsfactory(root.ScrollMagic||(root.jQuery&&root.jQuery.ScrollMagic),root.gsap,root.gsap||root.TweenMax||root.TweenLite,root.gsap||root.TimelineMax||root.TimelineLite);}}(this,function(ScrollMagic,Gsap,Tween,Timeline){ ... }
(lines 28-43 in animation.gsap.js)
This is basically where the gsap module is loaded. In the latest version of gsap, objects like TweenMax and TimelineMax are wrapped as a member of the gsap module so the gsap object is not equivalent to either TweenMax or TimelineMax. This is why when Tween.to is called later, it is not a function (gsap object doesn't have a key called to).
To solve the issue, I modified the above code as below:
(function(root,factory){if(typeofdefine==='function'&&define.amd){// AMD. Register as an anonymous module.define(['ScrollMagic','gsap','TweenMax','TimelineMax'],factory);}elseif(typeofexports==='object'){// CommonJS// Loads whole gsap package onto global scope.vargsap=require("gsap/dist/gsap")||require("gsap");// TweenMax/TimelineMax will be global in v2. In v3, they will be on the gsap objectfactory(require('scrollmagic'),gsap,TweenMax||gsap.TweenMax,TimelineMax||gsap.TimelineMax);}else{// Browser globalsfactory(root.ScrollMagic||(root.jQuery&&root.jQuery.ScrollMagic),root.gsap,root.TweenMax||root.TweenLite||root.gsap.TweenMax||root.gsap.TweenLite,root.TimelineMax||root.TimelineLite||root.gsap.TimelineMax||root.gsap.TimelineLite);}}(this,function(ScrollMagic,Gsap,Tween,Timeline){ ... }
After fixing this, there is another bug in line 275 of animation.gsap.js:
if(parseFloat(TweenLite.version)>=1.14){ ... }
Here, TweenLite is not defined before so you will get a undefined error in the console. To solve it, just replace TweenLite with Tween.
How to reproduce the issue
Load the scripts for ScrollMagic and gsap of the above version in the page.
Initialize a controller, create a scene with setTween, and add the scene to the controller.
Load the page in the browser (I'm using Chrome) and you should see the error.
Part of the code is pasted below for reference:
constcontroller=newScrollMagic.Controller();constscene=newScrollMagic.Scene({triggerElement: '#demo',duration: '100%',reverse: true}).setTween('#animate-element',{// some css properties}).addTo(controller);
The text was updated successfully, but these errors were encountered:
I'm having a similar problem. Here is the code and error msg.
Uncaught TypeError: Cannot read property 'to' of undefined
at O.Scene.f.setTween (animation.gsap.js:1)
at HTMLDocument. (themagic.js:1)
at e (jquery-3.4.1.min.js:1)
at t (jquery-3.4.1.min.js:1)
$(function() { // wait for document ready
// init
var controller = new ScrollMagic.Controller({
globalSceneOptions: {
triggerHook: 'onEnter',
}
});
// get all images
var images = document.querySelectorAll(".image");
// create scene for every image
for (var i = 0; i < images.length; i++) {
new ScrollMagic.Scene({
triggerElement: images[i]
})
.setTween(images[i], 0.5, {scale: 1.1})
.addIndicators()
.addTo(controller);
}
Version
ScrollMagic
: 2.0.8Gsap
: 3.5.1I am using ScrollMagic with React and webpack. Tricky configurations are needed to get the code compiled with webpack but I think the main problem lies in the source code itself.
Issue
I appreciate all the efforts made by the development team to accommodate different versions of
gsap
inanimation.gsap.js
. Since the latest version ofgsap
wrapsTweenMax
,TimelineMax
,TweenLite
,TimelineLite
, etc. into thegsap
object, the current version ofanimation.gsap.js
doesn't work with the lastestgsap@^3.5.1
.All the following code snippets are taken from
scrollmagic/uncompressed/plugins/animation.gsap.js
.The error is related to the function
Scene.setTween
. The following is the error message shown in the console whensetTween
is called:Backtracking where the variable
Tween
is initialized, I found the following chunk of code which caused the problem:(lines 28-43 in
animation.gsap.js
)This is basically where the
gsap
module is loaded. In the latest version ofgsap
, objects likeTweenMax
andTimelineMax
are wrapped as a member of thegsap
module so thegsap
object is not equivalent to eitherTweenMax
orTimelineMax
. This is why whenTween.to
is called later, it is not a function (gsap
object doesn't have a key calledto
).To solve the issue, I modified the above code as below:
After fixing this, there is another bug in line 275 of
animation.gsap.js
:Here,
TweenLite
is not defined before so you will get aundefined
error in the console. To solve it, just replaceTweenLite
withTween
.How to reproduce the issue
ScrollMagic
andgsap
of the above version in the page.setTween
, and add the scene to the controller.Part of the code is pasted below for reference:
The text was updated successfully, but these errors were encountered: