1

I'm making a mobile site, and I need to disable the native iphone overflow scrolling. To do so, I called preventDefault on the touchmove function, but the problem is that I also need to get the position of the mouse release once the user calls the mouseup event. How can you call the mouseup event even after calling preventDefault on the touchmove event?

My code right now looks like:

document.ontouchmove = function(e){
e.preventDefault();
} 

$(document).mousedown(function(e){
clickPosition = e.pageX;
});

$(document).mouseup(function(e){
releasePosition = e.pageX;
var positionDifference = clickPosition - releasePosition;
});
1
  • Not a duplicate if I understand him correctly, he wants to kill the default behaviour of touchmove and provide his own implementation to capture beginning\ending.
    – Kyle Muir
    Jul 7, 2013 at 7:13

1 Answer 1

0

Like this:

http://jsfiddle.net/KyleMuir/KGXb6/

use .trigger() to pass your params to your other function (http://api.jquery.com/trigger/)

However, for your example of capturing the beginning\end you would probably want to do something like this: http://jsfiddle.net/KyleMuir/KGXb6/3/

In this example, I create a variable outside of the event scopes for click position which constantly gets overridden on mousedown, then referenced on mouse up, a bit cleaner than using trigger.

If something needed to be done after mousedown, then you could use trigger to call into some function.

Hope this helps :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.