javascript - Swipe effect sensibility - Stack Overflow

i trying to use the swipe effect for a mobile app. i have tested and works to change page. but its very

i trying to use the swipe effect for a mobile app. i have tested and works to change page. but its very sensitive. lot of times i want only to scroll and he change the page.

it is possible to fixed the sensibility on touchscreen on this event?

here is my code:

$(document).on('swipeleft', '[data-role="page"]', function(event){    
    if(event.handled !== true) // This will prevent event triggering more then once
    {    
        var nextpage = $(this).next('[data-role="page"]');
        // swipe using id of next page if exists
        if (nextpage.length > 0) {
            $.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
        }
        event.handled = true;
    }
    return false;         
});

$(document).on('swiperight', '[data-role="page"]', function(event){   
    if(event.handled !== true) // This will prevent event triggering more then once
    {      
        var prevpage = $(this).prev('[data-role="page"]');
        if (prevpage.length > 0) {
            $.mobile.changePage(prevpage, {transition: "slide", reverse: true}, true, true);
        }
        event.handled = true;
    }
    return false;            
});

i trying to use the swipe effect for a mobile app. i have tested and works to change page. but its very sensitive. lot of times i want only to scroll and he change the page.

it is possible to fixed the sensibility on touchscreen on this event?

here is my code:

$(document).on('swipeleft', '[data-role="page"]', function(event){    
    if(event.handled !== true) // This will prevent event triggering more then once
    {    
        var nextpage = $(this).next('[data-role="page"]');
        // swipe using id of next page if exists
        if (nextpage.length > 0) {
            $.mobile.changePage(nextpage, {transition: "slide", reverse: false}, true, true);
        }
        event.handled = true;
    }
    return false;         
});

$(document).on('swiperight', '[data-role="page"]', function(event){   
    if(event.handled !== true) // This will prevent event triggering more then once
    {      
        var prevpage = $(this).prev('[data-role="page"]');
        if (prevpage.length > 0) {
            $.mobile.changePage(prevpage, {transition: "slide", reverse: true}, true, true);
        }
        event.handled = true;
    }
    return false;            
});
Share Improve this question edited May 13, 2013 at 13:41 Omar 31.7k9 gold badges72 silver badges116 bronze badges asked May 3, 2013 at 17:34 user2232273user2232273 4,97416 gold badges51 silver badges76 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

In jQuery Mobile, you need to set new values for the horizontal and vertical drag distance horizontalDistanceThreshold and verticalDistanceThreshold.

Note that you need to bind the change to mobileinit event and the code should be placed into <head> after loading jQuery js file and before loading jQuery-Mobile js.

<script src="jquery.js"></script>

<script>
$(document).bind("mobileinit", function(){
 $.event.special.swipe.horizontalDistanceThreshold = '100'; // default 30px
 $.event.special.swipe.verticalDistanceThreshold = '150'; // default 75px
});
</script>

<script src="jquery-mobile.js"></script>

Reference: Swipe event - jQuery Mobile

adjust the swipe thresholds like this

$.swipe.defaults.threshold.x = '30'; //for horizontal swiping sensitivity
$.swipe.defaults.threshold.y = '10'; //for vertical swiping sensitivity

just add these codes to change the global sensitivity of the swipes of your application and do your usual codes after putting the code above

to directly change the sensitivity on a certain element you can do something like this

$('[data-role="page"]').swipe({ threshold: {x: 30, y: 20},
swipeLeft: function() { alert('swiped left') },
swipeRight: function() { alert('swiped right') }});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744296058a4567266.html

相关推荐

  • javascript - Swipe effect sensibility - Stack Overflow

    i trying to use the swipe effect for a mobile app. i have tested and works to change page. but its very

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信