malsup / cycle2

2nd gen cycling
899 stars 236 forks source link

Swipe plugin - triggering multiple times due to event on parent element #718

Open idodev opened 9 years ago

idodev commented 9 years ago

I've been trying to implement swipe on a cycle2 gallery but find the gallery is transitioning two slides at a time. Eventually I've found that this is due to having an additional swiperight event registered on the <body> for a mobile app 'drawer' that is revealed from the left hand edge. This event is affecting the gallery due to the following line (53):

start.origin.trigger( "swipe" )
    .trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );

On this line the trigger on <body> has been raised on touchend but the resulting swipe trigger is then raised on a child element also (the cycle gallery).

By modifying start.trigger to $this.trigger the event only fires on the element I wrote the trigger for, however this causes a raft of other problems from what I can see!

I've just loaded the touch events code from jquery.mobile and its working as hoped now. Don't know if you can grab any further inspiration from there? If you want me to dig in any further I'll be happy to, however if I'm being daft and doing something wrong I'd also appreciate a pointer :smiley: