日期:2014-05-16 浏览次数:20344 次
$(document).ready(function(){ $("#up_btn").hover(function(){ var new_num = parseInt($("#move_box").css("top")); $("#move_box").css("top",new_num+1); }) })
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <script src="http://code.jquery.com/jquery-latest.js"></script> <style> div { position:absolute; top:300px; left:200px; width:20px; height:20px; border:1px solid red; } </style> </head> <body> <button id="up_btn">hover</button> <div id="move_box"></div> <script> var timer; $(document).ready(function(){ $("#up_btn").hover(function(){ timer = setInterval(function(){ var new_num = parseInt($("#move_box").css("top")); $("#move_box").css("top",new_num+1); }, 30) }, function(){ clearInterval(timer); }) }) </script> </body> </html>
------解决方案--------------------
$(document).ready(function(){
$("#up_btn").hover(
setInterval(function(){
var new_num = parseInt($("#move_box").css("top"));
$("#move_box").css("top",new_num+1);
};
,1000)
)
})
试试。。