2013-05-02 30 views
8

Có thể điều chỉnh khoảng cách cần thiết để kích hoạt sự kiện vuốt hay không, và nếu nó được thực hiện như thế nào ?.Điều chỉnh khoảng cách của một sự kiện vuốt trong điện thoại di động jquery

Đây mã im nói về:

$('.page2').bind('swiperight', function(event, ui){ 
    $.mobile.changePage(
     $('.page1'), 
     { 
      allowSamePageTransition: true, 
      transition: 'slide', 
      reverse: 'true', 
      showLoadMsg: false,      
      reloadPage: true, 
     } 
    ); 
    return false; 
}); 

Trả lời

9

Vâng, đó là có thể.

Bạn cần phải sửa đổi các thuộc tính:

  • $.event.special.swipe.horizontalDistanceThreshold (default: 30px) - Swipe dịch chuyển ngang phải có nhiều hơn này.

  • $.event.special.swipe.verticalDistanceThreshold (default: 75px) - Vuốt dịch chuyển dọc phải nhỏ hơn này.

này phải được thực hiện trong suốt sự kiện mobileinit, như thế này:

$(document).bind("mobileinit", function(){ 
    $.event.special.swipe.horizontalDistanceThreshold (default: 30px); 
    $.event.special.swipe.verticalDistanceThreshold (default: 75px); 
}); 

Một điều cuối cùng. Nếu bạn chưa bao giờ làm việc với mobileinit, sự kiện này phải được gọi trước jQuery di động được khởi tạo, như thế này:

<script src="jquery.js"></script> 
<script> 
    $(document).bind("mobileinit", function(){ 
     $.event.special.swipe.horizontalDistanceThreshold (default: 30px); 
     $.event.special.swipe.verticalDistanceThreshold (default: 75px); 
    }); 
</script> 
<script src="jquery-mobile.js"></script> 

Hãy nhìn vào các tài liệu chính thức here

+3

$ .event.special.swipe. horizontalDistanceThreshold = value; Đã làm các trick :) Thx – luQ

Các vấn đề liên quan