Delay CSS function in Jquery?

后端 未结 8 1248
自闭症患者
自闭症患者 2021-02-13 11:12

How can I delay a CSS change in jquery? Here is my code:

$(\"document\").ready(function() {
    $(\".pressimage img\").mouseenter(function() {
        $jq(this)         


        
8条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 11:34

    http://jsfiddle.net/loktar/yK5ga/

    Check that one out what I am doing is assigning the timeout to a variable and then clearing it on mouseover, so it wont fire if you do a mouse over quickly.

    $("document").ready(function() {
        var imgTimeout;
    
        $("img").hover(
            function() {
                clearTimeout(imgTimeout);
                $(this).css('z-index','1000');
        },
        function() {
            var element = $(this);
            imgTimeout = setTimeout(function(){element.css('z-index','1');}, 1000); 
        });
    });
    

提交回复
热议问题