Safari 移动版上的点击事件 jquery
Click event jquery on safari mobile
jquery 单击事件在移动版 Safari 中不起作用。
我尝试了 "curson: pointer",也尝试了 downgrade/upgrad jquery 版本,但没有任何效果。
https://codepen.io/larsen1982/pen/yWYNLj
$(".next").click(function(){
if(animating) return false;
animating = true;
这是 jquery:
http://thecodeplayer.com/uploads/js/jquery-1.9.1.min.js
在桌面、ipad 和 Android 智能手机浏览器中代码工作正常。
在 chrome 和 safari 移动版 (iphone) 中,按钮不起作用。
尝试添加 touchstart
:
$(".next").on('touchstart click', function(){
...
});
问题是 iPhone 不会引发点击事件。他们引发了 "touch" 事件。添加以下代码有效。
function touchHandler(event){
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type = "mousedown"; break;
case "touchmove": type = "mousemove"; break;
case "touchend": type = "mouseup"; break;
default: return;
}
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
function init() {
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
}
jquery 单击事件在移动版 Safari 中不起作用。
我尝试了 "curson: pointer",也尝试了 downgrade/upgrad jquery 版本,但没有任何效果。
https://codepen.io/larsen1982/pen/yWYNLj
$(".next").click(function(){
if(animating) return false;
animating = true;
这是 jquery: http://thecodeplayer.com/uploads/js/jquery-1.9.1.min.js
在桌面、ipad 和 Android 智能手机浏览器中代码工作正常。 在 chrome 和 safari 移动版 (iphone) 中,按钮不起作用。
尝试添加 touchstart
:
$(".next").on('touchstart click', function(){
...
});
问题是 iPhone 不会引发点击事件。他们引发了 "touch" 事件。添加以下代码有效。
function touchHandler(event){
var touches = event.changedTouches,
first = touches[0],
type = "";
switch(event.type)
{
case "touchstart": type = "mousedown"; break;
case "touchmove": type = "mousemove"; break;
case "touchend": type = "mouseup"; break;
default: return;
}
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(type, true, true, window, 1,
first.screenX, first.screenY,
first.clientX, first.clientY, false,
false, false, false, 0/*left*/, null);
first.target.dispatchEvent(simulatedEvent);
event.preventDefault();
}
function init() {
document.addEventListener("touchstart", touchHandler, true);
document.addEventListener("touchmove", touchHandler, true);
document.addEventListener("touchend", touchHandler, true);
document.addEventListener("touchcancel", touchHandler, true);
}