我一直在尝试使用 jQuery 的 animate() 创建一个简单的练习页面,以便在按钮按下时为一些 div 设置动画,但它不起作用。我在第 29 行遇到了一个未捕获的语法错误,$(.red).animate
......为什么会发生这种情况?
<!DOCTYPE html>
<html>
<head>
<title>ANIMATE WITH JQUERY</title>
<meta charset = "utf8">
<link rel = "stylesheet" href = "anim.css">
<script src = "jq/jquery-1.10.2.js"></script>
</head>
<body>
<button id = "but1">animate 1</button>
<button id = "but2">animate 2</button>
<div class = "red"></div>
<div class = "red"></div>
<div class = "red"></div>
<div id = "blue"></div>
<div id = "grey"></div>
<script>
$(document).ready(function() {
$('#but1').click(animateOne);
$('#but2').click(animateTwo);
});
function animateOne() {
$('.red').animate({margin-left:"200"},{duration:2000});
$('#blue').animate({margin-top:"30"},{duration:1000});
$('#grey').animate({margin-bottom:"200"},{duration:1500});
}
function animateTwo() {
$('.red').animate({margin-left:"400"},{duration:2000});
$('.red').animate({opacity:"0.2"},{duration:3000});
$('#blue').animate({margin-top:"30"},{duration:1000});
$('#grey').animate({margin-bottom:"200"},{duration:1500px});
}
</script>
</body>
</html>