Created
July 29, 2011 14:43
-
-
Save kpozin/1113949 to your computer and use it in GitHub Desktop.
Fix for jQuery Mobile's scrolling and taphold behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function fixScrollAndTapHold() { | |
var $document = $(document); | |
var isScrolling = false; | |
var lastX, lastY, lastT, scrollTimeout; | |
$document.bind("touchstart mousedown click", function(e) { | |
lastT = e.originalEvent.timeStamp; | |
}); | |
$document.bind("scroll", function(e) { | |
var t = e.originalEvent.timeStamp; | |
if (!t) { | |
return; | |
} | |
var x = window.pageXOffset; | |
var y = window.pageYOffset; | |
var dT = t - lastT; | |
var dX = Math.abs(x - lastX); | |
var dY = Math.abs(y - lastY); | |
var dMax = Math.max(dX, dY); | |
lastT = t; | |
lastX = x; | |
lastY = y; | |
var speed = dMax / dT; | |
if (speed >= 0.1 || dMax >= 10) { | |
isScrolling = true; | |
} | |
clearTimeout(scrollTimeout); | |
scrollTimeout = setTimeout(function() { | |
isScrolling = false; | |
}, 500); | |
}); | |
/** | |
* @return {Boolean} | |
*/ | |
$.mobile.isScrolling = function() { | |
return isScrolling; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment