jQuery: How to check if the mouse is over an element

前端 未结 6 2063
庸人自扰
庸人自扰 2021-01-11 13:16

I have a deferred function that binds a mouseenter event:

$(window).load(function(e) {
  var $container = $(\'.container\');
  $container.mouseenter(function         


        
6条回答
  •  醉酒成梦
    2021-01-11 13:21

    With jQuery 1.7+ you're going to want to use .on(): http://api.jquery.com/on/

    $(document).ready(function(){
        $('body').on("mouseover", "your_element_selector_here", function() {
            // do stuff here
        });
    });
    

    .live is deprecated. You could also put any other events in .on as well, depending on what you need. :hover doesn't work because it only works with specific elements and it's css based.

    Using this in conjunction with an offset detection approach for before the page finishes loading will get you where you want to be.

提交回复
热议问题