這個(gè)鼠標(biāo)放到一個(gè)位置就一直在動(dòng)
<!DOCTYPE html>
<html>
<head>
? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
? ? <title></title>
? ? <style>
? ? div {
? ? ? ? width: 500px;
? ? ? ? height: 50px;
? ? ? ? padding: 5px;
? ? ? ? margin: 5px;
? ? ? ? float: left;
? ? ? ? border: 1px solid #ccc;
? ? ? ??
? ? }
? ??
? ? .left {
? ? ? ? background: #bbffaa;
? ? }
? ? button{
? ? ? ? width:200px;
? ? ? ? height:100px;
? ? }
? ? #q1{
? ? ? ? top:200px;
? ? }
? ? #q2{
? ? ? ? top:160px;
? ? }
? ? .right {
? ? ? ? background: yellow;
? ? ? ? display: none;
? ? }
? ? </style>
? ? <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
? ? <h2>通過(guò)toggle切換顯示與隱藏</h2>
? ? <div class="left">顯示到隱藏</div>
? ? <div class="right">隱藏到顯示</div>
? ? <button id="q1">直接show-hide動(dòng)畫(huà)</button>
? ? <button id="q2">直接hide-show動(dòng)畫(huà)</button>
? ? <script type="text/javascript">
? ? $("button:first").mousemove(function() {
? ? ? ? $(".left").toggle({
? ? ? ? ? ? ? ? duration:3000,
? ? ? ? ? ? ? ? complete:function(){
? ? ? ? ? ? ? ? ? ? $(this).css('width','800px'
? ? ? ? ? ? ? ? ? ? )
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })
? ? });
? ? </script>
? ? <script type="text/javascript">
? ? $("button:last").mousemove(function() {
? ? ? ? $(".right").toggle(3000)
? ? });
? ? </script>
</body>
</html>
2016-12-17
兩種方法解決此問(wèn)題 ?第一種 ?把你需要操作的button進(jìn)行固定定位放在你需要的地方 ?第二種 ?mousemove換成mouseover就會(huì)只執(zhí)行一次?
2016-12-17
事件在一次一次的累加 ?所以如果你鼠標(biāo)觸發(fā)了button:first的事件但是沒(méi)有及時(shí)移開(kāi)的話 ?div.left每移動(dòng)一像素button:first就會(huì)觸發(fā)一次 ?你的mousemove事件在排隊(duì)執(zhí)行