Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
gareth

Responsive draggable menu

Recommended Posts

Hi,

 

I have simple menu that I want to drag from 5% of the screen to 100%. 

// changing this to "100%" does not work
var maxX = 320

Draggable.create(".menu", {
  type:"x",
  throwProps:true, 
  edgeResistance: 1,
  maxDuration:0.3, 
   bounds: {maxX:maxX, minX:0}, 
    snap: {
    x: [0, maxX]
  }
  
});

The menu works fine if I supply a pixel value for the bounds and snap points. It is possible to use % ?

 

thanks,

Gareth

See the Pen xOdYqY by garethj (@garethj) on CodePen

Link to comment
Share on other sites

ok so I can just grab the screen width (but will have to update on resize)

var maxX =  window.innerWidth;

which brings me to my next question how do you control when the snap is triggered ? at the moment it looks like you have to exceed 50% for the menu to snap either way. Is is possible to change this to say 25% i.e if I drag past 25% the menu will snap to 100% ?

Link to comment
Share on other sites

You can use a function...

See the Pen bZWvja by osublake (@osublake) on CodePen

 

If you're trying to create a swipe effect, I think it feels more natural if you don't use positional constraints. I use the velocity tracker to determine the direction to move it if it exceeded some number of pixels, similar to how hammerjs does it.

  • Like 2
Link to comment
Share on other sites

ah! thanks so much for demo, it is spot on. I agree it does feel more natural. 

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