I’ve written a small animation script, a couple of snowflakes falling down. It all works great, but I’m wondering weather I can make it a bit more efficient, simply because I don’t consider myself that much of a good programmer and I’m sure I made some mistakes here or there. Just trying to learn. Thank You in advance!
Here’s the link to jsfiddle
or the script itself:
$(document).ready(function ()
{
var arr = ["1000", "2000", "3000", "4000"];
var pause = 0;
var myDiv = $('div');
function scroll()
{
if (pause == 0)
{
myDiv.each(function (index)
{
myDiv.eq(index).delay(arr[index]).animate({"margin-top":"150px","opacity":"1"},
{
duration:3000,
queue: true,
complete: function ()
{
$(this).css({"margin-top":"0","opacity":"0"});
pause = 0;
scroll();
}
});
});
}
}
scroll();
});
http://jsfiddle.net/2gxkX/9/
I make a few tweaks here are there. Overall your code is good.
myDivs.eq(index)replaced with$(this)"margin-top"withtopsince they’re absolutely positioned"0"etc replaced with0since jquery knows how to handle numbersEDIT:
simple version: http://jsfiddle.net/2gxkX/10/