2011-11-25 152 views
0

我一直在搜索一下,并试图确定如何通过html元素(如div)执行简单的滑动事件,以便在JavaScript中发生某些操作。iPad滑动手势移动Safari浏览器

<div id="swipe_me"> 
Swipe Test 
</div> 

有人可以告诉我或指向我的一些文件?

回答

0

javascript。

东西有点像(未经测试的代码)

   onInitialized: function(e, slider) { 

    var time = 1000, // allow movement if < 1000 ms (1 sec) 
     range = 100, // swipe movement of 50 pixels triggers the slider 
     x = 0, t = 0, touch = "ontouchend" in document, 
     st = (touch) ? 'touchstart' : 'mousedown', 
     mv = (touch) ? 'touchmove' : 'mousemove', 
     en = (touch) ? 'touchend' : 'mouseup'; 

    slider.$window 
     .bind(st, function(e){ 
      // prevent image drag (Firefox) 
      e.preventDefault(); 
      t = (new Date()).getTime(); 
      x = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX; 
     }) 
     .bind(en, function(e){ 
      t = 0; x = 0; 
     }) 
     .bind(mv, function(e){ 
      e.preventDefault(); 
      var newx = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX, 
      r = (x === 0) ? 0 : Math.abs(newx - x), 
      // allow if movement < 1 sec 
      ct = (new Date()).getTime(); 
      if (t !== 0 && ct - t < time && r > range) { 
       if (newx < x) { slider.goForward(); } 
       if (newx > x) { slider.goBack(); } 
       t = 0; x = 0; 
      } 
     }); 
}