Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Touch Events [Swipe Left/ Right] to a image gallery

Tags:

jquery

I have been working on image gallery [html5] and its working fine in desktop version i would like to add touch based events for Ipad/Tablet devices.

Can you please suggest how to add touch based events using javascript/jquery.

Thanks, Srinivas

like image 717
Srinivas Avatar asked Mar 22 '13 08:03

Srinivas


2 Answers

This jQuery plugin works well. http://www.netcu.de/jquery-touchwipe-iphone-ipad-library Easy to use. Ex:

$('.slideshow').touchwipe({
 wipeLeft: function() {$('.slideshow').cycle('next');},
 wipeRight: function() { $('.slideshow').cycle('prev');},
 min_move_x: 60         
});
like image 77
Adam Avatar answered Nov 15 '22 12:11

Adam


You can use this function

swiperight or another direction

// jquery mobile
    $("#id").swiperight(function() {
        //do some with $.mobile.changePage function
    });
    $("#id").swipeleft(function() {
        //do some $.mobile.changePage function
    });

// javascript
document.ontouchmove = function(e) {
    var target = e.currentTarget;
    while(target) {
        if(checkIfElementShouldScroll(target))
            return;
        target = target.parentNode;
    }

    e.preventDefault();
};
like image 37
JohannesAndersson Avatar answered Nov 15 '22 12:11

JohannesAndersson