為什么點(diǎn)擊按鈕“左移”“右移”之后,第二次就沒(méi)有效果了呢
代碼如下:
<!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動(dòng)畫特效</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每執(zhí)行一次在原始位置加50所以不會(huì)變動(dòng),改為+=50px會(huì)每次增加50。
你還有一個(gè)其他的問(wèn)題就是你的左移實(shí)現(xiàn)不了,因?yàn)闆](méi)有定義div的right 。 ?并且你這 都是+50px。。。。。 ?
問(wèn)問(wèn)題之前也稍微認(rèn)真一點(diǎn)吧,太馬虎了可沒(méi)有人回答你!對(duì)平臺(tái)的同學(xué)和老師都尊重些