滑动效果敏感度 [英] Swipe effect sensibility
问题描述
我尝试对移动应用程序使用滑动效果.我已经测试过并致力于更改页面.但它非常敏感.很多时候我只想滚动,然后他就换了页面.
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?
这是我的代码:
$(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;
});
推荐答案
在jQuery Mobile中,您需要为水平和垂直拖动距离horizontalDistanceThreshold
和verticalDistanceThreshold
设置新值.
In jQuery Mobile, you need to set new values for the horizontal and vertical drag distance horizontalDistanceThreshold
and verticalDistanceThreshold
.
请注意,您需要将更改绑定到mobileinit
事件,并且在加载jQuery js文件之后和加载jQuery-Mobile js之前,应将代码放置在<head>
中.
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
这篇关于滑动效果敏感度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!