標籤:
首先先來看一下jquery中stop()的用法
- stop()用於在動畫執行前停止正在執行的動畫
- stop(stopAll,goToEnd)的兩個參數為布爾值;
- stopAll:true/false;是否停止對象接下來所有的動畫;
- goToEnd:true/false;停止方式是直接將動畫播放至結束位置還是停止在當前位置。
jquery中的fadeIn、fadeOut,slideDown、slideUp如果設定stop(false,false),動畫停止的位置將被記錄下來,下一次動畫走到上次被停止的位置就會結束。而我們需要的是下一次動畫依舊能夠完整執行,所以需要設定stop(true,true),將動畫直接播放至結束。
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <script src="//cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script> <style type="text/css"> .wodejifen_box{ position:relative; width:80px; height:34px; overflow: visible; } .wodejifen{ height:34px; font-size: 12px; width:80px; line-height: 34px; border:1px solid red ; text-align: center; } .wodejifen_content{ position:absolute; width:150px; top:34px; left:0; border:1px solid black; padding:5px; display:none; } .wodejifen_content li{ border-bottom:1px solid black; line-height:20px; list-style: none; padding:0; } </style></head><body><div class="wodejifen_box"> <div class="wodejifen"> 我的積分 </div> <ul class="wodejifen_content"> <li>內容0000000</li> <li>內容1111111</li> <li>內容2222222</li> <li>內容3333333</li> </ul></div> <script type="text/javascript"> $(‘.wodejifen‘).mouseover(function(event){ $(‘.wodejifen_content‘).stop(true,true).slideDown(150); }).mouseout(function(event){ $(‘.wodejifen_content‘).stop(true,true).slideUp(150); }); </script></body></html>
關於jquery內建動畫效果的stop()問題