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

后端 未结 26 1775
太阳男子
太阳男子 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:51

    If you use Modernizr, it is very easy to use Modernizr.touch as mentioned earlier.

    However, I prefer using a combination of Modernizr.touch and user agent testing, just to be safe.

    var deviceAgent = navigator.userAgent.toLowerCase();
    
    var isTouchDevice = Modernizr.touch || 
    (deviceAgent.match(/(iphone|ipod|ipad)/) ||
    deviceAgent.match(/(android)/)  || 
    deviceAgent.match(/(iemobile)/) || 
    deviceAgent.match(/iphone/i) || 
    deviceAgent.match(/ipad/i) || 
    deviceAgent.match(/ipod/i) || 
    deviceAgent.match(/blackberry/i) || 
    deviceAgent.match(/bada/i));
    
    function Tipsy(element, options) {
        this.$element = $(element);
        this.options = options;
        this.enabled = !isTouchDevice;
        this.fixTitle();
    };
    

    If you don't use Modernizr, you can simply replace the Modernizr.touch function above with ('ontouchstart' in document.documentElement)

    Also note that testing the user agent iemobile will give you broader range of detected Microsoft mobile devices than Windows Phone.

提交回复
热议问题