iOS automatic hover fix?

前端 未结 8 688
春和景丽
春和景丽 2020-12-04 17:01

Is there a jQuery plugin or JavaScript script that automagically loops through each CSS hover (found in an external stylesheet) and binds it with a double touchdown event?

相关标签:
8条回答
  • 2020-12-04 17:45

    There is no jQuery plugin that I know of to do such a thing.

    You cannot trigger a css psuedo class such as ":hover". You can however loop through the anchor elements and add a css class ".hover" on touchstart and touchend events as follows:

        var pageLinks = document.getElementsByTagName('a');
    for(var i = 0; i < pageLinks.length; i++){
        pageLinks[i].addEventListener('touchstart', function(){this.className = "hover";}, false);
        pageLinks[i].addEventListener('touchend', function(){this.className = "";}, false);
    }
    

    To add a double finger tap gesture recognizer, you can use a plugin such as: http://plugins.jquery.com/project/multiswipe

    0 讨论(0)
  • 2020-12-04 17:47

    Here's an optimized version of the jQuery code provided by Richard JP Le Guen:

    $(document).ready(function() {
    
        $('a').each(function() {
    
            var clicked = false;
    
            $(this).bind('click', function() {
    
                if(!clicked) return !(clicked = true);
            });
        });
    });
    
    0 讨论(0)
提交回复
热议问题