A plugin to capture swipe and move events on any element of webpage on ipad, iphone, android and other smart phones. Plugin works on all modern browsers on desktop, iphone, ipad, andriod phones and tables.
This script goes into head section
<!-- Include jQuery Library --> <script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js" type="text/javascript"> </script> <!-- Include swipe Library --> <script src="swipe.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $(".swipe").swipe({ PreventDefault: true, EnableMouse: true, Distance: 100, OnTouch: function (detail) { $("#touch").html("Touch Details : { clientX : " + detail.client.x + ", clientY : " + detail.client.x + ", pageX : " + detail.page.x + ", pageY : " + detail.page.y + ", screenX : " + detail.screen.x + ", screenY : " + detail.screen.y + "}"); }, OnMove: function (detail) { $("#move").html("Move Details : { xchange:" + detail.diffx + ", ychange : " + detail.diffy + ", clientX : " + detail.client.x + ", clientY : " + detail.client.x + ", pageX : " + detail.page.x + ", pageY : " + detail.page.y + ", screenX : " + detail.screen.x + ", screenY : " + detail.screen.y + "}"); }, OnSwipe: function (detail) { $("#swipe").html("Swipe Details : { direction :" + detail.direction + ", distance : " + detail.distance + ", speed : " + detail.speed + ", time: " + detail.time + "}"); }, OnEnd: function () { } }); }); </script>
HTML Example
<div class="swipe"> Swipe Area </div> <div id="touch"></div> <div id="move"></div> <div id="swipe"></div>
Option | Default | Description |
---|---|---|
PreventDefault | true |
true | false
|
EnableMouse | true |
true | false
By default library track mouse based touch, move and swipe. |
Distance | 100 |
Integer
Swipe function will be called only if distance is greater than set value. |
OnTouch |
null
|
function(detail) { /* detail: { client: { x , y }, page: { x, y }, screen: { x, y } } */ }
client means current clientX and clientY coordinates
|
OnMove |
null
|
function(detail) { /* detail : { diffx, diffy, client: { x, y }, page: { x, y }, screen: { x, y } } */ }
diffx means difference in x from last move
|
OnSwipe |
null
|
function(detail) { /* detail: { direction, distance, speed, time } */ }
direction : 'u' | 'd' | 'l' | 'r'
|
OnEnd |
null
|
function() { }
Called when swipe ends. |