admin管理员组文章数量:1401681
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
2 Answers
Reset to default 5In 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') }});
本文标签: javascriptSwipe effect sensibilityStack Overflow
版权声明:本文标题:javascript - Swipe effect sensibility - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744296058a2599347.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论