幫忙看下代碼哪里錯了,為什么點擊按鈕沒效果呢
<!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>
2016-06-28
需要在div的css樣式中加入定位哦,position:absoulute;left:50px;top:50px; 要不left:"+=50"不起作用的
然后你在點擊試試,就好用了
2016-06-28
懂了,因為left是position的時候用到的,不定位的話用margin-left就可以嘍,感謝!
2016-06-28
這個是css的東西,為什么會影響jquery的效果呢?能解釋下嗎?