这是我的动画实验,它主要按我的预期工作。但是,我希望动画一一发生。这意味着具有 id1 的 div 先执行动画,然后具有 id2 的 div ......等等。我使用 for 循环来完成这个技巧,但动画发生得太快了。谁能让我知道如何使动画一个一个地发生,而不是几乎同时为所有 div 设置动画。提前感谢任何好心的帮助者。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>jQuery Animation - jsFiddle demo by dennisboys</title>
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
.items {
float: left;
margin-right: 3px;
height: 50px;
width: 50px;
background-color: lightblue;
}
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
/*
Javascript logics:
1. One click on each div can generate a full animation.
- using a for loop to do the div animation
*/
$(document).ready(function(){
// global variable for holding a fixed height increase
var newHeight = 50;
// global counter to keep track of which div is being clicked
var counter = 1
// count the number of divs on this page, a total of 9
var divCount = $('.items').length;
$('.items').click(
function(){
for(i=1; i<=divCount; i++){
// increase the global variable by 50
newHeight += 50;
// set random width and height
var randomWidth = Math.floor( Math.random() * 201 + 50 ); // generate a number from 50 - 250
var randomHeight = Math.floor( Math.random() * 201 + 50 );
$('#' + i).animate( {width:randomWidth, opacity:'0.3'}, 1000 );
$('#' + i).animate( {height:randomHeight, opacity:'1' }, 1000 );
$('#' + i).animate( {width:'50', opacity:'1'}, 1000 );
$('#' + i).animate( {height:newHeight, opacity:'1' }, 1000 );
}
});
});
});//]]>
</script>
</head>
<body>
<div class="items" id="1" status="true"></div>
<div class="items" id="2" status="true"></div>
<div class="items" id="3" status="true"></div>
<div class="items" id="4" status="true"></div>
<div class="items" id="5" status="true"></div>
<div class="items" id="6" status="true"></div>
<div class="items" id="7" status="true"></div>
<div class="items" id="8" status="true"></div>
<div class="items" id="9" status="true"></div>
</body>
</html>
这是jsfiddle页面。