為什么div沒有一直右移或者左移呢,我并沒有設(shè)置邊界啊
<!DOCTYPE html>
<html>
<head>
? ? <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
? ? <title>jQuery動(dòng)畫特效</title>
? ? <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
</head>
<body>
<input id="btn1" type="button" value="左移"/>
<input id="btn2" type="button" value="右移"/>
<div style="border:3px solid red;width:130px;margin:100px;position: absolute">你點(diǎn)擊我就動(dòng)!</div>
</body>
<script type="text/javascript">
? ? $("#btn1").bind("click",function(){
? ? ? ? $("div").stop();
? ? ? ? $("div").animate(
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? left:"-=50px"
? ? },3000)
? ? });
? ? $("#btn2").bind("click",function(){
? ? ? ? $("div").stop();
? ? ? ? $("div").animate(
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? left:"+=50px"
? ? },3000)
? ? });
</script>
</html>
2016-05-09
因?yàn)閘eft:"-=50px"設(shè)置的左移距離為50,而不是無(wú)限制移動(dòng),當(dāng)設(shè)置left:"-=200px"的時(shí)候,就會(huì)左移200px,已經(jīng)移出頁(yè)面外了,所以并不是界限的問(wèn)題。
2016-05-17
看不出來(lái),但是你這個(gè)stop方法沒有用處
2016-05-09
你代碼里面只設(shè)置一次移動(dòng)50px,所以你點(diǎn)一次最好也只是移動(dòng)50px,你點(diǎn)多幾次,它就會(huì)移出邊界了