我的网站上有一些滑动功能。我刚刚注意到它不能用于某些ipad和ipad minis所以我将它们插入我的mac进行调试
这是我收到一个event.layerX和event.layerY在webkit中被破坏和弃用的时候。它们将在不久的将来从发动机中移除
在ipad mini上它实际上打破了网站上的js而没有抛出错误
这是我正在使用的代码
if( /Android|webOS|iPhone|iPad|iPadMini|iPod|BlackBerry/i.test(navigator.userAgent) ) {
var maxTime = 1000,
// allow movement if < 1000 ms (1 sec)
maxDistance = 50,
// swipe movement of 50 pixels triggers the swipe
target = jQuery('.pageSize'),
startX = 0,
startTime = 0,
touch = "ontouchend" in document,
startEvent = (touch) ? 'touchstart' : 'mousedown',
moveEvent = (touch) ? 'touchmove' : 'mousemove',
endEvent = (touch) ? 'touchend' : 'mouseup';
target.bind(startEvent, function(e) {
// prevent image drag (Firefox)
// e.preventDefault();
startTime = e.timeStamp;
startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
}).bind(endEvent, function(e) {
startTime = 0;
startX = 0;
}).bind(moveEvent, function(e) {
// e.preventDefault();
var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
currentDistance = (startX === 0) ? 0 : Math.abs(currentX - startX),
// allow if movement < 1 sec
currentTime = e.timeStamp;
if (startTime !== 0 && currentTime - startTime < maxTime && currentDistance > maxDistance) {
if (currentX < startX) {
// swipe left code here
slide("forward", pageSize);
}
if (currentX > startX) {
// swipe right code here
slide("back", pageSize);
}
startTime = 0;
startX = 0;
}
});
}
我看过WebKit issues with event.layerX and event.layerY
任何人都可以推荐任何东西吗?