Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created June 4, 2010 22:12
Show Gist options
  • Save paulirish/426012 to your computer and use it in GitHub Desktop.
Save paulirish/426012 to your computer and use it in GitHub Desktop.
// here's a rewrite of the amelie.js to avoid global variables and eval via setTimeout(string..
// http://icant.co.uk/ie6-amelie/
if (document.all && !window.XMLHttpRequest){(function(){
var x = 1,
when = 0,
str, dir, fil;
function amelie() {
if (x == 2) {
x = 0;
}
if (x == 0) {
str = 0;
dir = 0;
when = Math.floor(Math.random() * 10*1000) + 2000;
setTimeout(amelie, when);
} else {
str = Math.floor(Math.random() * 2) + 2;
dir = Math.floor(Math.random() * 360);
setTimeout(amelie, 500);
}
var fil = "progid:DXImageTransform.Microsoft.MotionBlur(strength=" + str + ",direction=" + dir + ",enabled='true')";
document.body.style.filter = fil;
x++;
}
setTimeout(amelie, 1000);
})()}
@mathiasbynens
Copy link

Why if (x == 0) {} and not if (!x)?
Why str = 0; dir = 0; instead of just str = dir = 0;?
Why x * 10 * 1000 and not x * 1e4?

THINK OF THE IE6 PERFORMANCE MAN

@phiggins42
Copy link

@math, var str = dir = 0 globalizes dir

@mathiasbynens
Copy link

@phiggins42: Even when it's called from inside an anonymous function? Also note that in this case it’s not exactly var str = dir = 0; but str = dir = 0 — the variables str and dir have already been declared.

@phiggins42
Copy link

@math - you are totally right. I thought the gist has changed since your initial comment and the 0's were in the var declaration for str && dir ... /me stands corrected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment