JQ中的show跟hide方法为什么鼠标已经移开了还不停的在哪动呢

我把鼠标放到div上两三次,他就不停的在那动,这个怎么解决啊。

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
</head>
    <style type="text/css">
        div{width:100px;height:50px;background:#000;}
        p{width:100px;height:200px;background:red;display:none;margin-top:-2px;}
    </style>
    <script src="jquery.js">       
    </script>
    <script type="text/javascript">
    $(function(){
            $('div').hover(function(){
               $('p').slideDown(500);
            });
            $('div').mouseout(function(){
                $('p').slideUp(500);
            });
        });
    </script>
    <body>

<div></div>
<p></p>
</body>
</html>
阅读 3.9k
3 个回答

可能是hover的影响,hover([over,]out),你设置了over,但是没有设置out的状态,建议你详细看看hover方法的使用;另外你上面的那段是可以这样写的:

$(function(){

$('div').hover(function(){
   $('p').slideDown(500);
},
function(){
    $('p').slideUp(500);
});

});

slideDown和slideUp前加一句.stop()
$('p').stop().slideUp(500)

清除动画stop()

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进