Jump to content
GreenSock

HaunGo

Basic swipe event to call a function

Recommended Posts

Hello..

 

I'm having trouble finding a very basic swipe example.. ..  I don't need to drag anything around.. .. I just need to listen to a swipe up or down and call the appropriate function.

 

I've got a little something now based off of some examples, but again.. .. i end up dragging the stage round when I just want to listen for a swipe direction.

 

Any suggestions?

 

Here is my simple code:

var DD = Draggable.create($("#stage"),
{
	type:'y',
	lockAxis:true,
	onRelease:function()
	{
		var dir = this.getDirection("start");
		console.log('swipe! onDragStart() ' + dir)
		if (dir === "up"){
			next();
		}else if(dir === "down"){
			prev();
		}
	}	
});

 

 

ALSO, I tried attaching it to the body, but the only direction that would log was "right".

 

Thanks, 

Link to comment
Share on other sites

Hi HaunGo  :)

 

pls try this :

 

var D = document.createElement('div');
Draggable.create(D,{
  type:'y',
  lockAxis : true ,
  trigger:$("#stage"),
  onDragEnd:function(){
    console.log( this.getDirection("start") == "up" ? 'next' : 'back' );
  }
});
  • Like 2
Link to comment
Share on other sites

This works great Diaco   THANKS !

 

 

Now, I'll figure out WHY it works.  ;)    

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