jQuery Mobile swipe through history

Implementing swipe events with jQuery Mobile is really easy.
This example shows how you can control the browsers back and forward buttons by swiping in the left or right direction.

With a body with id theBody,

<body id="theBody">

you can use the following piece of javascript to navigate back and forward using swipe events through the pages stored in the browsing history.

		jQuery(document).ready(function() {
			jQuery('#theBody').live('swipeleft',function(event){
				window.history.back();
				event.preventDefault();
			});
			jQuery('#theBody').live('swiperight',function(event){
				window.history.forward();
				event.preventDefault();
			});
		});

You can view a demo here.


This entry was posted in tech blerf and tagged , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">