Online Snippets Library

Swiperight and Swipeleft effect in jQuery

Here we learn ,how to create swipe effect in jQuery.

Syntax

$("selector").on("swiperight",function(event){...}) AND $("selector").on("swipeleft",function(event){...})

Swiperight Example

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"> </script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"> </script>
<title>Swiperight effect in JQuery</title>
</head>
<body>
<div style="border: 1px solid ;" id="divId" >Swipe Right - Please do not swipe outside the border!</div>
</body>
</html>
Javascript
$(document).ready(function(){
$("#divId").on("swiperight",function(){
  alert("You swiped right!");
});
});

Swipeleft Example

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.2.min.js"> </script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"> </script>
<title>Swipeleft effect in JQuery</title>
</head>
<body>
<div style="border: 1px solid ;" id="divId1" >Swipe Left - Please do not swipe outside the border!</div>
</body>
</html>
Javascript
$(document).ready(function(){
$("#divId1").on("swipeleft",function(){
  alert("You swiped left!");
});
});