Нажмите событие JQuery на Safari Mobile - PullRequest
0 голосов
/ 08 мая 2019

Событие jquery click не работает в мобильном сафари.

Я попробовал "curson: указатель", также понизить / обновить версию 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

В браузерах SmarthPone для настольных ПК, iPad и Android код работает нормально. В Chrome и Safari Mobile (iphone) кнопки не работают.

Ответы [ 2 ]

1 голос
/ 08 мая 2019

Попробуйте добавить touchstart:

$(".next").on('touchstart click', function(){
    ...
});
0 голосов
/ 08 мая 2019

Проблема в том, что айфоны не генерируют события кликов. Они поднимают «сенсорные» события. Добавление в следующий код работает.

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);    
}
...