Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default wipe for some wipes using jQuery touchwipe

I'm using this wonderful plugin to capture wipe events on mobile devices: http://www.netcu.de/jquery-touchwipe-iphone-ipad-library

I'm using the code in the source of that page to get my image gallery cycling as it should be. However, my image gallery is the full width of the screen. Unfortunately, touchwipe seems to be preventing the default up and down wipes from scrolling up and down the page. Is there a way to make it use the default behaviour, except when other behaviour is specified?

$(document).ready(function() {
    $('#imagegallery').cycle({
        timeout: 0,
        fx: 'scrollHorz',
        next: '#next',
        prev: '#prev' 
    });

    $("#imagegallery").touchwipe({
        wipeLeft: function() {
            $("#imagegallery").cycle("next");
        },
        wipeRight: function() {
            $("#imagegallery").cycle("prev");
        }
    });
});

I'm also open to other alternatives to achieving this same effect (other plugins, other methods). Thanks!

like image 452
thugsb Avatar asked May 27 '11 18:05

thugsb


1 Answers

With this small patch to the jquery.touchwipe library:

if(Math.abs(dx) >= config.min_move_x) {
     cancelTouch();
     if(dx > 0) {
-        config.wipeLeft();
+        config.wipeLeft(e);
     }
     else {
-        config.wipeRight();
+        config.wipeRight(e);
     }
  }
  else if(Math.abs(dy) >= config.min_move_y) {
     cancelTouch();
     if(dy > 0) {
-        config.wipeDown();
+        config.wipeDown(e);
     }
     else {
-        config.wipeUp();
+        config.wipeUp(e);
     }
  }

you can then change your code to selectively call e.preventDefault():

$(document).ready(function() {
    $('#imagegallery').cycle({
        timeout: 0,
        fx: 'scrollHorz',
        next: '#next',
        prev: '#prev' 
    });

    $("#imagegallery").touchwipe({
        wipeLeft: function(e) {
            e.preventDefault();
            $("#imagegallery").cycle("next");
        },
        wipeRight: function(e) {
            e.preventDefault();
            $("#imagegallery").cycle("prev");
        },
        preventDefaultEvents: false
    });
});

(I've submitted the patch to the plugin author.)

like image 71
darnlotusblossom Avatar answered Nov 10 '22 23:11

darnlotusblossom