I have few elements in my HTML page which are only images and tooltip. I wanted them to animate randomly based on the animation I have done on the CSS part.
Currently all the elements will animate together when the page is loaded, I do no want this.
I am thinking of calling the CSS class from jQuery one by one, but looking at the number of elements and since it is just a basic translation animation, is there any better way to do this?
Here are the elements:
<div class="twitter-animate">
<div id="twitter-wrap"><a href="#" id="twitter"><img src="img/link-twitter.png"></a></div>
<div id="twitter-tooltip"><span>Tweet!</span></div>
</div>
<div id="youtube-wrap"><a href="#" id="youtube"><img src="img/link-youtube.png"></a></div>
<div id="youtube-tooltip"><span>YouTube</span></div>
<div id="facebook-wrap"><a href="#" id="facebook"><img src="img/link-fb.png"></a></div>
<div id="facebook-tooltip"><span>Facebook</span></div>
<div id="newspaper-wrap"><a href="#" id="newspaper"><img src="img/link-newspaper.png"></a></div>
<div id="newspaper-tooltip"><span>Newspaper</span></div>
<div id="www-wrap"><a href="#" id="www"><img src="img/link-www.png"></a></div>
<div id="www-tooltip"><span>Put your URL!</span></div>
<div id="email-wrap"><a href="#" id="email"><img src="img/link-email.png"></a></div>
<div id="email-tooltip"><span>Mail me!</span></div>
For the sake of simplicity I’m going to assume you want your elements to to be translated from left to right. The tooltips are also irrelevant, so I’ll remove them.
The first thing you need to do is add a common class to all your elements. Here I added
shareas a class:Then your CSS should look something like this…
Then you need a little bit of javascript to fire off the first animation, and then listen when each trasition ends to fire off the next one…
You can find it all put together here: http://jsfiddle.net/HYAWj/