admin管理员组文章数量:1321046
I want to detect if users swipe from the edge or not before I open the panel with $("#panel").panel("open");
. Here is the code
$("#main").on("swiperight",function(event){
var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event,
coords = [data.pageX, data.pageY];
console.log(coords);
});
However the coords
didn't return anything because I got error:
Uncaught TypeError: Cannot read property 'touches' of undefined
So is there a way to get coordinate when swipe happens?
Or is there an easy way to detect if the staring position is from the left edge instead?
Thanks.
I want to detect if users swipe from the edge or not before I open the panel with $("#panel").panel("open");
. Here is the code
$("#main").on("swiperight",function(event){
var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event,
coords = [data.pageX, data.pageY];
console.log(coords);
});
However the coords
didn't return anything because I got error:
Uncaught TypeError: Cannot read property 'touches' of undefined
So is there a way to get coordinate when swipe happens?
Or is there an easy way to detect if the staring position is from the left edge instead?
Thanks.
Share Improve this question asked Nov 20, 2013 at 23:40 HP.HP. 19.9k56 gold badges159 silver badges258 bronze badges 1- Similar: stackoverflow./questions/24163202/… – trante Commented Jun 12, 2014 at 8:14
3 Answers
Reset to default 4Try below in jqm 1.4+, worked for me, adjust the edge trim value accordingly, 50 was good for me
$( "div.ui-page" ).on( "swiperight", function( e ) {
if ( e.swipestart.coords[0] <50) {
// your logic
}
});
this is for x coordinate similarly you can get y from coords[1]
this will work for any screen size:
$("#main").on("swiperight",function( event ){
// take 15% of screen good for diffrent screen size
var window_width_15p = $( window ).width() * 0.15;
// check if the swipe right is from 15% of screen (coords[0] means X)
if ( event.swipestart.coords[0] < window_width_15p) {
// open your panel
$("#panel").panel("open");
}
});
You can do something like this.
$('#main').on('touchstart', function(e) {
var xPos = e.originalEvent.touches[0].pageX;
if(xPos == 0) { //Keep in mind the margin of failure from 0, when user touches.
//Handle edge swipe
}
});
本文标签: javascriptDetect swipe from edge in jQuery MobileStack Overflow
版权声明:本文标题:javascript - Detect swipe from edge in jQuery Mobile - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742093695a2420415.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论