Handle mouse up/down event
Description
The following code shows how to handle mouse up/down event.
Example
<!-- ww w. j ava2 s. c o m-->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script
src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="content">
<p>Some content, drag to see the distance</p>
</div>
</div>
<script type='text/javascript'>//<![CDATA[
var coords = [0, 0],
threshold = 100;//in pixels
$(document).bind('vmousedown', function (event) {
coords = [event.offsetX, event.offsetY];
}).bind('vmouseup', function () {
var distance = Math.sqrt(Math.pow(coords[0] - event.offsetX, 2) + Math.pow(coords[1] - event.offsetY, 2));
if (distance > threshold) {
alert('Swipe (' + Math.floor(distance) + 'px)');
} else {
alert('Click (' + Math.floor(distance) + 'px)');
}
});
</script>
</body>
</html>