Jump to content
Search Community

Draggable Snap points

gareth test
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

Hi Gareth, 

 

Thanks for the demo.

 

Pleas see if this works for you
http://codepen.io/GreenSock/pen/KwXJzO

 

I changed the snaps Array of values to a function that checks to see if the end value is less than 50% of the menu's width.

 

snap:function(end){
     //if less than halfway go back to fully open
   return (end < -menuWidth/2) ? -menuWidth : 0; 
  }

 

I think we may have to look into why your Array of points wasn't working. Seems ThrowProps was always preferring the "most negative" value as opposed to the closest value. [edit: wrong assumption, see below]

 

Carl.

Link to comment
Share on other sites

The snapPoints do work. I think I was doing something wrong in my initial test. Please try

 

snapPoints = [-menuWidth, 0];
Draggable.create(menu, {type:"x",dragClickables:true, edgeResistance:1,throwResistance:0,maxDuration: 0.5, bounds:"#menuBounds", lockAxis:true, throwProps:true,snap:snapPoints,
});
 
  • Like 1
Link to comment
Share on other sites

Hm, strange that the second one is not working for you.

This is what I see in Chrome on a MAC

 

http://www.greensock.com/forums-support-files/throwProps-snap.mp4

 

Perhaps, give it another try with a clear cache?

 

Does anyone else have this pen here: http://codepen.io/GreenSock/pen/gbGqwj?editors=001performing differently than in my video?

The menu should snap back to its OPEN state if you drag or throw it LESS than 50% of the distance to its closed state.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

It looks like the root of this problem had to do with some inconsistencies in the way Chrome reports bounds. More recent versions of Chrome seem to have shifted algorithms that can result in it being about 1 - 1.1 pixel off. So you could have resolved things by adjusting your snapping values accordingly:

snapPoints = [-menuWidth+1.1, 0];

However, I have updated Draggable to work around the issue internally so that shouldn't be necessary in the future. I have attached a preview of the upcoming release so that you can test it out. Please let us know if it works well for you.

GSAP_1.15.2_preview2.zip

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