iPad/iPhone hover problem causes the user to double click a link

后端 未结 26 1708
太阳男子
太阳男子 2020-11-27 09:18

I have some websites I built times ago, that use jquery mouse events...I just got an ipad and i noticed that all the mouse over events are translated in clicks...so for inst

26条回答
  •  孤城傲影
    2020-11-27 09:44

    You can use click touchend ,

    example:

    $('a').on('click touchend', function() {
        var linkToAffect = $(this);
        var linkToAffectHref = linkToAffect.attr('href');
        window.location = linkToAffectHref;
    });
    

    Above example will affect all links on touch devices.

    If you want to target only specific links, you can do this by setting a class on them, ie:

    HTML:

    Prevent extra click on touch device

    Jquery:

    $('a.prevent-extra-click').on('click touchend', function() {
        var linkToAffect = $(this);
        var linkToAffectHref = linkToAffect.attr('href');
        window.location = linkToAffectHref;
    });
    

    Cheers,

    Jeroen

提交回复
热议问题