Jump to content
Search Community

Basic swipe event to call a function

HaunGo test
Moderator Tag

Go to solution Solved by Diaco,

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

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

  • Solution

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

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