Jump to content
Search Community

Check if animated property was modified outside

c64 test
Moderator Tag

Go to solution Solved by Carl,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi! 

How could I check if tweened property was modifed outside by code or user interaction during the tween? 

There is scrollable div(s) on my page (actually price tables) with scrollLeft DOM property animated by TweenLite, but also scrollLeft is changed if user scrolls the div manually. I couldn't find a way to distinguish which of the following is the cause for scrollLeft change - tween processing or user interaction (each fires jquery event "scroll").

But I'd like to kill tween of the div if user starts scrolling so it stays under user control. 

 

Thank you..

Link to comment
Share on other sites

Hi c64  :)

 

Welcome to the GreenSock forum.

 

I'm not sure I'm completely following your question, but it sounds like _gsTransform may be what you're looking for. From the docs:

  • All transforms are cached in a _gsTransform object attached to the element, so you can tween individual properties without worrying that they'll be lost. You don't need to define all of the transform properties on every tween - only the ones you want to animate. You can read the transform-related values anytime, like element._gsTransform.scaleX. If you'd like to clear those values (including the transform applied to the inline style of the element), you can do TweenLite.set(element, {clearProps:"transform"});. If you'd like to force GSAP to re-parse the transform data from the css (rather than use the data it had recorded from previous tweens), you can pass parseTransform:true into the config object.

https://greensock.com/docs/#/HTML5/Plugins/CSSPlugin/

 

If that doesn't solve the problem, could you please provide a simplified CodePen for us? More info about that:

 

https://greensock.com/forums/topic/9002-read-this-first-how-to-create-a-codepen-demo/

 

Happy tweening.

:)

  • Like 2
Link to comment
Share on other sites

  • Solution

I'm a little confused about what you are asking as well.

 

If you are using ScrollToPlugin there is an autoKill property that should kill the tween when a user scrolls.

 

https://greensock.com/docs/#/HTML5/GSAP/Plugins/ScrollToPlugin/

 

Like, Craig mentioned, a simplified demo that clearly replicates the problem will really help us offer a solution.

  • Like 3
Link to comment
Share on other sites

Yep, I suspect you're looking for that autoKill feature that we've already got baked in to make your life easier. 

 

For the record, there's no way to know that a value is edited elsewhere other than what we do inside the plugin which is to record the value we set, and then next time we go to set a new value, we compare the previous one with the current one. If it's different, we know we didn't set it, so SOMETHING else did. 

 

In other words, if I set scrollTop to 100 and then on the next tick, I check scrollTop and it's 130, something else messed with it. 

 

Does that help at all?

  • Like 4
Link to comment
Share on other sites

Hello, guys! Thanks for your answers.

 

Sorry for not being clear. But you got the idea, the autoKill property shoud do the the trick. I was not using ScrollTo plugin syntax, but created my tweens this way:

TweenLite.to(this, 0.42, {scrollLeft: lefts, ease: Power1.easeInOut}). I don't know if it makes any difference.

Link to comment
Share on other sites

For the record, there's no way to know that a value is edited elsewhere other than what we do inside the plugin which is to record the value we set, and then next time we go to set a new value, we compare the previous one with the current one. If it's different, we know we didn't set it, so SOMETHING else did. 

 

I wonder if that could be exposed via GSAP API so I could override set() function... onBeforeUpdate callback or something. I mean, what if GSAP engine would provide that callback with value that 'should' be set if Tween goes normally and user could modify that value and set it. 

 

I'm afraid of being unclear again, and probably should just read the sources and docs.

Link to comment
Share on other sites

I think the ModifiersPlugin may help you. It allows you to intercept and modify the values the engine is planning on setting on each update of a tween.

From what I understand you could probably run your own logic in the modifier function to check for outside forces interfering.

 

Watch video and read: https://greensock.com/1-19-0/

Yes that's what I was looking for! Thanks!

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...