<html?xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>無標題文檔</title>
<script?src="http://libs.baidu.com/jquery/1.9.0/jquery.js"?type="text/javascript"></script>
?<style>
????????????.child{background:black;width:100px;height:100px;margin:0?auto;position:relative}
????????????button{margin:0?20px;}
????????????div{margin:0?auto;width:200px;height:200px;}
????????????button{margin-top:20px;}
????????</style>
????</head>
????
????<body>
????????<div?class="child"></div>
????????<div>
????????<button?id="left">左移</button>
????????<button?id="right">右移</button>
????????</div>
????</body>
????<script>
????????$(function?()?{
????????????$("#left").bind("click",?function?()?{
????????????????$(".child").animate({
????????????????????right:"+=50px"
????????????????},2000)
????????????});
????????????$("#right").bind("click",?function?()?{
????????????????$(".child").animate({
????????????????????left:"+=50px"
????????????????},2000)
????????????})
????????})
????</script>
</html>
2016-05-31
因為你是相對于body進行定位,假如你先點了左移,那么是有效的,但是你點右移,就會出錯,它無法在保證距離左邊的情況再實現右邊。嗯應該是這么回事。解決方法就是只操作一個值,不要right和left都用。
2016-05-31
在chrome上點擊多次并未失效。