為什么不能同時(shí)用left:“+=50px”和right:“”+=50px
使用animate()方法進(jìn)行動(dòng)畫,為什么不能同時(shí)用left:“+=50px”和right:“”+=50px;
同時(shí)用的話,會(huì)存在問題:
<!DOCTYPE html>
<html>
? ? <head>
? ? ? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
? ? ? ? <title>jQuery動(dòng)畫特效</title>
? ? ? ? <style type="text/css">
#block{
position: relative;
width: 50px;
height: 50px;
background-color: red;
margin:10px;
}
? ? ? ? </style>
? ? ? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
? ? </head>
? ??
? ? <body>
? ? ? ? <div id="block"></div>
? ? ? ? <form action="#">
? ? ? ? <input type="button" value="左移" />
? ? ? ? <input type="button" value="右移" />
? ? ? ? </form>
? ? ? ? <script type="text/javascript">
? ? ? ? $(function(){
? ? ? ? $("input[value='左移']").bind('click',function(){
? ? ? ? $("#block").animate({right:"+=50px"},500);
? ? ? ? });
? ? ? ? $("input[value='右移']").bind('click',function(){
? ? ? ? // $("#block").animate({left:"+=50px"},500); ?這里改變left的屬性為什么存在問題?
? ? ? ? $("#block").animate({right:"-=50px"},500);?
? ? ? ? });
? ? ? ? });
? ? ? ? </script>
? ? </body>
</html>
2016-05-17
如果這樣寫,你往右走了,在想往左,就不會(huì)從當(dāng)前的位置移動(dòng)了,而是會(huì)從初始值移動(dòng)
2016-04-12
我試了兩次 ?都可以的啊 ? 這個(gè)不是同時(shí)左右移 ?是點(diǎn)擊按鈕觸發(fā) ?按鈕是左移就坐 ?沒有什么沖突的 ?
你的錯(cuò)誤提示是什么?
2016-04-10
我試了一下,沒問題啊
2016-04-10
就像一個(gè)人叫你向左,另一個(gè)人叫你向右,你能左右都同時(shí)進(jìn)行?
2016-04-10
不同元素,同時(shí)左右移沒有問題,對(duì)同一個(gè)元素而言,向左又向右,太不科學(xué)了吧