How to disable mouseover event with javascript/jquery?

后端 未结 3 380
不思量自难忘°
不思量自难忘° 2021-01-26 19:23

In my code a function execute when user mouseover on a div for first time and the function take like 30 seconds to complete, during that 30 seconds if user mouseover the same di

3条回答
  •  广开言路
    2021-01-26 20:00

    Use jQuery's on() and off() with some sort of callback, for example :

    $("#myElementID").on('mouseover', myFunction);
    
    myFunction(e) {
        var myElement = e.target;
        myElement.off('mouseover', myFunction);
        //do something that takes 30 seconds
        myElement.animate({top: 1000}, 30000, function() { //callback
            myElement.on('mouseover', myFunction);
        });
    }
    

提交回复
热议问题