I found a jQuery script online that creates multiple span elements below the viewport (each containing the same small animated gif) and moves each of these to the top of the page at different speeds and then repeats the loop over and over.
Currently this uses about 10% of my processor time. Is there anyway to reduce this CPU usage even further? I have reduced the number of span elements, but this didn't help very much.
I read about setting setInterval, which I have done and it helped somewhat, but I still believe it is too high for what I believe is a simple animation.
var easings=[]
$.each($.easing,function(i,v){
if ($.isFunction(v))
easings.push(i)
})
function randomEasing(){
return easings[Math.floor(Math.random()*easings.length)]
}
function cloud(x,y,toX,toY,speed){
var easingUp=randomEasing()
$('<span class="cloud">')
.text(easingUp)
.css({
top:y,
left:x
})
.animate({
top:toX,
left:toY
},{
duration:speed||500,
complete: function(){
$(this).remove();
cloud(x,y,toX,toY,speed)
},
specialEasing: {
top: easingUp,
height: randomEasing()
}
})
.appendTo('body')
}
function randy(from,to){
return Math.floor(Math.random()*(to-from)+from)
}
$(function(){
var bottom=$(window).height()+90
var right=$(window).width()-200
for(var left=50;left<right;left+=50){
cloud(left,bottom+90,-70,"-="+randy(-10,10),randy(10000,24000))
}
})
jQuery.fx.interval = 60;
Is there anything else I can do to reduce CPU usage, or is this the best I can do with jQuery and should be looking at other solutions?