為什么點擊按鈕“左移”“右移”之后,第二次就沒有效果了呢
代碼如下:
<!DOCTYPE html>
<html>
? ? <head>
? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
? ? ? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
? ? ? ? <link href="style.css" rel="stylesheet" type="text/css"/>
? ? ? ? <title>jQuery動畫特效</title>
? ? </head>
? ??
? ? <body>
? ? ? ? <button id="btn1">左移</button>
? ? ? ? <button id="btn2">右移</button>
? ? ? ? <div>77</div>
? ? ? ? <script type="text/javascript">
? ? ? ? ?$("div").css({"position":"absolute"});
? ? ? ? ? ? $("#btn1").bind("click",function(){
? ? ? ? ? ? ? ? $("div").animate({right: "+50px"},3000);
? ? ? ? ? ? })
? ? ? ? ? ? $("#btn2").bind("click",function(){
? ? ? ? ? ? ? ? $("div").animate({left:"+50px"},3000);
? ? ? ? ? ? })
? ? ? ? </script>
? ? ? ??
? ? </body>
</html>
2016-07-05
+50px每執行一次在原始位置加50所以不會變動,改為+=50px會每次增加50。
你還有一個其他的問題就是你的左移實現不了,因為沒有定義div的right 。 ?并且你這 都是+50px。。。。。 ?
問問題之前也稍微認真一點吧,太馬虎了可沒有人回答你!對平臺的同學和老師都尊重些