Javascript 在jQuery Mobile中检测从边缘刷卡
在我用Javascript 在jQuery Mobile中检测从边缘刷卡,javascript,jquery,jquery-mobile,mobile,touch,Javascript,Jquery,Jquery Mobile,Mobile,Touch,在我用$(“#panel”).panel(“open”)打开面板之前,我想检测用户是否从边缘刷卡。这是密码 $("#main").on("swiperight",function(event){ var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event, coords = [data.pageX, data.pageY]; console.log(coords); }); 但是,co
$(“#panel”).panel(“open”)打开面板之前,我想检测用户是否从边缘刷卡代码>。这是密码
$("#main").on("swiperight",function(event){
var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event,
coords = [data.pageX, data.pageY];
console.log(coords);
});
但是,coords
没有返回任何内容,因为我得到了错误:
未捕获的TypeError:无法读取未定义的属性“touchs”
那么,有没有一种方法可以在发生滑动时获得坐标
或者有没有一种简单的方法来检测凝视的位置是从哪里来的
改为左边缘
谢谢。你可以这样做
$('#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
}
});
在jqm 1.4+中尝试以下内容,对我有效,相应地调整边缘修剪值,50对我很好
$( "div.ui-page" ).on( "swiperight", function( e ) {
if ( e.swipestart.coords[0] <50) {
// your logic
}
});
$(“div.ui-page”)。在(“SwiperRight”上,函数(e){
如果(例如swipestart.coords[0]这将适用于任何屏幕大小:
$("#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");
}
});
$(“#main”)。打开(“swiperight”,函数(事件){
//对于不同的屏幕尺寸,取屏幕质量的15%
var window_width_15p=$(window).width()*0.15;
//检查右击是否从屏幕的15%开始(coords[0]表示X)
if(event.swipestart.coords[0]
touchstart
不会告诉我是否刷卡以及刷卡的时间。因为我还设置了$.event.special.swipe.horizontaldestancethreshold=120;
以确保刷卡的时间足够长。为了澄清我回答了您提出的两个问题。要获得完整的解决方案,您需要结合自己的解决方案来检测SwiperRight事件和我的示例,以查看触摸屏何时启动。如果触摸屏启动位置不正确,您只需不处理边缘滑动即可。类似: