我animate在jQuery中的函数有问题.我在本地工作,该函数不会动画我的div元素.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("button").click(function() {
$("div").animate({left: '250px'});
});
});
</script>
</head>
<body>
<div style="position:absolute"> Animate Box </div>
<button> Start </button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
动画工作得很好,但元素没有移动,因为它没有位置或起点:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div {position: relative; left:0;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("button").click(function() {
$("div").animate({left: '250px'});
});
});
</script>
</head>
<body>
<div> Animate Box </div>
<button> Start </button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)