Simulate Hover using jQuery

前端 未结 4 416
星月不相逢
星月不相逢 2020-12-19 04:03

Given the existing \"buttons\"

HTML:

 
                      
相关标签:
4条回答
  • 2020-12-19 04:43

    I would use setInterval and jQuery.trigger('mouseover', …).

    0 讨论(0)
  • 2020-12-19 04:54
    #MB .list a:hover,
    #MB .list a:focus,
    #MB .list .active a {
      /* hover styles */
    }
    

    (I've simplified your selectors a bit, I would also suggest trying to remove the outer div as these are often unnecessary and the ul alone is enough)

    Javascript hover:

    function setHover() {
        if ($('#MB .list .active').next().length) {
            $('#MB .list .active').next().addClass('active').end().removeClass('active');
        } else {
            $('#MB .list .active').removeClass('active');
            $('#MB .list li:first-child').addClass('active');
        }
    }
    
    setInterval(setHover, 1000);
    
    0 讨论(0)
  • 2020-12-19 04:58

    Define a third selector like

    #MB .list li a:hover,#MB .list li a:focus,#MB .list li a.simFocus { … }

    and then add and remove the "simFocus" class time-based per javascript code.

    0 讨论(0)
  • 2020-12-19 04:58

    Try adding onClick="return true" in your link a href tag

    <a href="../about.php" onMouseOver="mopen('m2')" onMouseOut="mclosetime()" onClick="return true">About us</a> 
    

    the onClick="return true" should simulate a cursor hovering over then leaving the hover area. effectivly giving you a hover effect.

    keep in mind, ur finger has to touch the button for the hover effect to take place, which means the user will only see the change for a second or two before the link loads a page.

    0 讨论(0)
提交回复
热议问题