亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

幫忙看下代碼哪里錯了,為什么點擊按鈕沒效果呢

<!DOCTYPE html>

<html>

? ? <head>

? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

? ? ? ? <title>jQuery動畫特效</title>

? ? </head>

? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>

? ? <script type="text/javascript">

? ? $(function(){

? ? ? ? $(".left").bind("click",function(){

? ? ? ? ? ? $("div").animate({

? ? ? ? ? ? ? ? left: "-=50px"

? ? ? ? ? ? },3000)

? ? ? ? })

? ? ? ? $(".right").bind("click",function(){

? ? ? ? ? ? $("div").animate({

? ? ? ? ? ? ? ? left: "+=50px"

? ? ? ? ? ? },3000)

? ? ? ? })

? ? })

? ? </script>

? ? <body>

? ? ? ? <div style="width:100px;height:100px;background:red;margin:0 auto;"></div>

? ? ? ? <button type="button" class="left" >left</button>

? ? ? ? <button type="button" class="right" >right</button>

? ? </body>

? ??

</html>


正在回答

3 回答

需要在div的css樣式中加入定位哦,position:absoulute;left:50px;top:50px; 要不left:"+=50"不起作用的

然后你在點擊試試,就好用了

0 回復 有任何疑惑可以回復我~

懂了,因為left是position的時候用到的,不定位的話用margin-left就可以嘍,感謝!

0 回復 有任何疑惑可以回復我~

這個是css的東西,為什么會影響jquery的效果呢?能解釋下嗎?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
jQuery基礎課程
  • 參與學習       154733    人
  • 解答問題       7289    個

加入課程學習,有效提高前端開發速度

進入課程

幫忙看下代碼哪里錯了,為什么點擊按鈕沒效果呢

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號