jquery求指点 我写了一个setInterval 但是想hover停止,mouseout继续,求指点
jquery求指点 我写了一个setInterval 但是想hover停止,mouseout继续,求指点
下面我写好了,但是mouseout不能继续,求指点
- HTML code
<div class="div1">1</div>
- JScript code
$(document).ready(function() { picTimer = setInterval(function() {showPic();},1000); function showPic() { $(".div1").animate({marginTop:"40px"},500); $(".div1").animate({marginTop:"-40px"},500); } $(".div1").hover( function() { clearInterval(picTimer); } ,function(){ } ); }); [解决办法]
- HTML code
<!DOCTYPE HTML><html> <head> <meta charset="gbk" /> <title></title> <style> div { position:absolute; left:200px; top:200px; border:1px solid red; width:20px; height:20px; } </style> </head> <body> <div class="div1">1</div> <script src="http://code.jquery.com/jquery-latest.js"></script> <script>$(document).ready(function() { picTimer = setInterval(showPic, 1000); function showPic() { $(".div1").animate({marginTop:"40px"},500); $(".div1").animate({marginTop:"-40px"},500); } $(".div1").mouseover(function(){ $(this).stop(); clearInterval(picTimer); }).mouseout(function(){ picTimer = setInterval(showPic, 1000); }) }); </script> </body></html>