Detect mouse hover on page load with jQuery

前端 未结 5 1533
渐次进展
渐次进展 2021-01-19 04:01

I wanted to detect whether the mouse was over an element when the web page was loaded. It appears this is not possible with jQuery - mouseover, hover etc. require a mouse mo

5条回答
  •  盖世英雄少女心
    2021-01-19 04:15

    Why not! :)

    Here is a solution of mine:

    DEMO

    Code from the demo:

    function handler(ev) {
        var target = $(ev.target);
        var elId = target.attr('id');
        if( target.is(".el") ) {
           alert('The mouse was over'+ elId );
        }
    }
    $(".el").mouseleave(handler);
    

提交回复
热议问题