This is my animation experiment, it works mostly as I expect. However, I want to animation happen one by one. That means the div with id1 does the animation first, then div with id2...etc. I use a for loop to do the trick but the animation happens just too fast. Could anyone let me know how I can make the animation happen one by one instead of animating all the divs almost simultaneously. Thanks in advance for any kind helpers.
<!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>
Here is the jsfiddle page.