Ok, scrub that.
I see that when you turn the animation off, it is still running behind the scenes (causing the page to be sluggish on older machines).
So, I added a line to the stopAnimation function which removes all of the inline CSS declarations from the animated elements.
This will have the effect or resetting them to their original position.
function stopAnimation(){
$("body").find('*').stop(true, true);
console.log(timeouts.length);
for (var i=0; i<timeouts.length; i++) {
clearTimeout(timeouts[i]);
}
$("#plane, #balloon1, #balloon2, #nearclouds, #farclouds").removeAttr('style');
}
It is a little bit hackish to hardcode these elements like this, but I don’t think you really want to add many more elements to animate, so in this case, I think it is ok to leave it like that.
Hey thank you. Ahh your in Germany. It’s only 1:53am were I am.
Really? I dont see that. I see when you turn it back on (on my resent striped demo) they all start from their default position. The plane of screen to the right - the clouds off screen to the left - the balloons at the top drifting down.
EDIT: I just dont want to unnecessarily hard code it as you say if I dont have too.
Well, you could add a class of “beingAnimated” to all elements that are well, being animated and just remove the inline styles from these elements, but this would add quite a bit more code to what you already have.
Put another way, do you want to add more elements to be animated in the future?
Probably. But remembering to add another item to the js as well would be no problem. See I just thought I could remove the css position from the js and place them in the css. When the js was running it would override the the css position. Then when turned off the css would kick in. Is this not how it would work? Therefore you had to add the hackish bit? If thats the case then no problem I’ll run with it. But if we can instead just remove the inline styles from the js that would be better yeah?
Nah, the way it works is that you specify the “off” position in the CSS.
Then the JS kicks in, places the element at its start point and animates to its end point over a specified period of time.
It does this over and over until the user klicks “off” at which point all inline styles are removed and the elements return to their “off” position which was specified in the CSS.
This also gives users with JS disabled a sane default.
The only hackish bit was specifying the elements by name in this line:
ew-we! Finally done with that! http://www.websitecodetutorials.com/ Thats took a long time to get right. But now when its turned off older computers like mine are much happier. CPU usage goes back down to 2% instead of the 75% it was before when off. Thanks Pullo
Can anyone figure out why in IE8 only when you click the animation to off the plane and the clouds disappear? Upon clicking a new page or reload they return. http://www.websitecodetutorials.com/.