我正在尝试使用 jquery animate 函数来为框设置动画,但这个简单的代码似乎让我感到厌烦。我不确定我弄错了什么?有时类似的代码可以完美运行,有时却显得非常困难。
<!doctype html>
<html>
<head>
<script src="jquery.js">
</script>
<style>
#main{
clear:both;
}
#boxes{
position:absolute;
width:75%;
}
#box1, #box2, #box3{
position:relative;
width:200px;
height:200px;
background-color:#FFD600;
margin:10px;
}
#buttons{
float:right;
}
input{
display:block;
width:150px;
}
</style>
<script>
$('document').ready(function(){
$("#left").bind('click', function(){
console.log('Left');
$('#box1').animate({x:"+=20px"});
});
});
</script>
</head>
<body>
<div id="main">
<div id="boxes">
<div id="box1">
</div>
<div id="box2">
</div>
<div id="box3">
</div>
</div>
<div id="buttons">
<input type="button" value="Left" id="left">
<input type="button" value="Right" id="right">
<input type="button" value="Top" id="top">
<input type="button" value="Bottom" id="bottom">
<input type="button" value="Height" id="height">
<input type="button" value="Width" id="width">
</div>
</div>
</body>
</html>
Try it在 JSFiddle 上。
最佳答案
关于javascript - 这段代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8351877/