iScroll Detecting click when scrolling

3,580 views
Skip to first unread message

ercgeek

unread,
Nov 23, 2011, 12:52:30 AM11/23/11
to isc...@googlegroups.com
The DIV I am using inside an iScroll contains clickable elements (as you normally have on an image gallery, for example). I would like to filter out the events and not respond to a "click" when it is part of teh swipe move that is used to scroll. So, if thh user touch-scrolls the "selected" image, the one clicked, does not change.
 
Is there a way to trap the click and discard it when iScroll is in the middle of a swipe motion?
 
Thanks for any help on this.
 
erc

Иван Миро

unread,
Nov 28, 2011, 3:30:39 AM11/28/11
to isc...@googlegroups.com
+1 same problem

Иван Миро

unread,
Nov 28, 2011, 4:10:05 AM11/28/11
to isc...@googlegroups.com

Иван Миро

unread,
Nov 28, 2011, 4:45:29 AM11/28/11
to isc...@googlegroups.com
I think there must be unbind for "touchcancel" and "mousewheel" but no idea how call this events.

Henrik Ammer

unread,
Jan 26, 2012, 6:46:31 AM1/26/12
to isc...@googlegroups.com
I solved it by adding a scrollingclass to the wrapper with the onScrollMove and remove it on onScrollEnd.

However that sparked the problem if the swipe is stopped by tapping/clicking on the wrapper. But that was solved by adding to the clickevents on the element that if it still had the scrolling class, remove it and do nothing more.

See the example here, http://pastebin.com/QVHUBPES

The page uses jQuery 1.7.1, a pulldown (#pull) and is on swedish. The wrapper id is content.

Ash Connell

unread,
Jun 13, 2012, 4:26:45 AM6/13/12
to isc...@googlegroups.com
I have tried so many variations of fixing this including patched versions of iScroll.js and tracking mouse movement etc. The solution i found was another variation of Henrik Ammer's... adding and removing classes still fires the click event AFTER you remove the class. preventing bubbling with stopPropagation will not work either. The perfect solution to this was by adding removing the class after 200ms. It can probably be less, but that works fine for me.

onScrollMove: function(){ $('a').addClass('scrolling'); },
onScrollEnd: function(e){ setTimeout(canClickNow, 200); function canClickNow(){ $('a').removeClass('scrolling'); } }

The items that get clicked have this event listener:

$('.scroller ul li a').live('mouseup', function(e) 
{

if(!$(this).hasClass('scrolling'))
{
// Do stuff
}
});

Or you could do if($(this).hasClass('scrolling')){ e.preventDefault(); } if you are not using custom events on the anchors.
Reply all
Reply to author
Forward
0 new messages