我的JavaScript代码似乎阻止了移动设备?
我在一页中有以下代码。 目前可以在桌面上正常工作。 左箭头向后导航。向右箭头向前。我想在home和end上添加一些东西 代码的滑动部分是我在网络搜索后得到的,除了几行,如果。。。其他的在这里做事 在Galagy S4上的移动Firefox上进行测试:该站点运行良好,但只有这一个站点包含了代码 结果:滑动不工作,但也单击“不确定”是否为“单击手机不工作”、“调整大小不工作”。。。换言之,它被粘在了页面上 我没有太多的工具在手机上调试我的JavaScript代码似乎阻止了移动设备?,javascript,events,mobile,key,swipe,Javascript,Events,Mobile,Key,Swipe,我在一页中有以下代码。 目前可以在桌面上正常工作。 左箭头向后导航。向右箭头向前。我想在home和end上添加一些东西 代码的滑动部分是我在网络搜索后得到的,除了几行,如果。。。其他的在这里做事 在Galagy S4上的移动Firefox上进行测试:该站点运行良好,但只有这一个站点包含了代码 结果:滑动不工作,但也单击“不确定”是否为“单击手机不工作”、“调整大小不工作”。。。换言之,它被粘在了页面上 我没有太多的工具在手机上调试 function checkKey(event) { v
function checkKey(event) {
var keyEvent = event || window.event,
keycode = (keyEvent.which) ? keyEvent.which : keyEvent.keyCode;
if(keycode == 37)
NavigateBackward();
else if(keycode == 39)
NavigateForward();
else
{
alert(keycode);
return true
}
return false;
}
document.onkeypress = checkKey;
var swipeFunc = {//Source:https://gist.github.com/localpcguy/1373518
touches : {
"touchstart": {"x":-1, "y":-1},
"touchmove" : {"x":-1, "y":-1},
"touchend" : false,
"direction" : "undetermined"
},
touchHandler: function(event) {
var touch;
if (typeof event !== 'undefined'){
event.preventDefault();
if (typeof event.touches !== 'undefined') {
touch = event.touches[0];
switch (event.type) {
case 'touchstart':
case 'touchmove':
swipeFunc.touches[event.type].x = touch.pageX;
swipeFunc.touches[event.type].y = touch.pageY;
break;
case 'touchend':
touches[event.type] = true;
if (swipeFunc.touches.touchstart.x > -1 && swipeFunc.touches.touchmove.x > -1) {
swipeFunc.touches.direction = swipeFunc.touches.touchstart.x < swipeFunc.touches.touchmove.x ? "right" : "left";
// DO STUFF HERE
if(swipeFunc.touches.direction === "left")
alert(swipeFunc.touches.direction);
else if(swipeFunc.touches.direction === "left")
alert(swipeFunc.touches.direction);
else
return true;
return false;
}
default:
break;
}
}
}
},
init: function() {
document.addEventListener('touchstart', swipeFunc.touchHandler, false);
document.addEventListener('touchmove', swipeFunc.touchHandler, false);
document.addEventListener('touchend', swipeFunc.touchHandler, false);
}
};
swipeFunc.init();
经过额外的测试,是刷卡功能阻止了一切。删除它并只保留代码的其他部分就可以了。但我当然希望它能起作用。