Jump to content
Search Community

draggable scroll + getvelocity

gibo
Moderator Tag

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

Posted

I'm not sure if this is a bug, or that I'm doing something slightly wrong.

 

      Draggable.create(".viewport", {type:"scroll",
        throwProps:true,
        onDragEnd:function() {
          console.log("velocity is: " + ThrowPropsPlugin.getVelocity(this.target, "scroll") + " and the duration is " + this.tween.duration() + " seconds.");
        }
      });
 
Using the property scroll always returns NaN, using another property such as rotation works as expected.
Posted

Well, the "scroll" type is a bit more tricky because Draggable has to create a special "scrollProxy" object that handles all the movement and velocity (due to the fact that browsers don't allow scrollTop or scrollLeft to overscroll - we have to use transforms or margins to accomplish that). You can get that ScrollProxy object directly on the Draggable instance itself (it's a property), and the ScrollProxy has "top" and "left" methods that get/set the vertical/horizontal scroll values. So to get the velocity of the vertical movement, for example, you could do this in your onDragEnd: 

console.log("velocity is: " + ThrowPropsPlugin.getVelocity(this.scrollProxy, "top") + " and the duration is " + this.tween.duration() + " seconds.");

Of course for the horizontal velocity, you'd check "left" instead of "top". 

 

Is that what you were looking for? 

Posted

Indeed it is, many thanks.

 

I couldn't find this in the docs, perhaps an example should be added to the Draggable documentation.

 

Thanks again.

Posted

Done. Added a note to the docs. 

  • Like 1

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...