我正在尝试更改div的颜色
当鼠标移出该div时,不在该div上返回5秒,然后更改div背景颜色
这是一些使div离开鼠标的时间的代码

<html>
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Effects - Animate demo</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <style>
    #effect { width: 240px; padding: 0.4em; position: relative; background: yellow; }
  </style>
  <script>
  var sec = 0;
        function pad ( val ) { return val > 9 ? val : "0" + val; }
        setInterval( function(){
            $("#effect").attr("name",pad(++sec%60));
        }, 1000);
        $(document).ready(function(){
        $("#effect").mouseout(function (){
            var time = $(this).attr("name");
            alert("at Mouse out:- "+time+" Second ");
        });
        });
  </script>
</head>
<body>
  <div id="effect" class="ui-widget-content ui-corner-all">ON Ready Status...
</div>
</body>
</html>
<script>
</script>


5秒后如何更改div颜色。的鼠标出来?

最佳答案

    $("#test").on('mouseenter', function() {
        $("#test").css('background-color', 'red');
    });


    $("#test").on('mouseleave', function() {
            var timer=self.setInterval(function() {
           $("#test").css('background-color', 'blue');
            window.clearInterval(timer);},5000);
    });
});


小提琴:http://jsfiddle.net/jsAgX/

10-05 20:34
查看更多