foo = document.getElementById("outer");
function cycleIt() {
if (client.browser.Firefox) {
foo.addEventListener("animationend", updateClassName, true);
} else {
foo.addEventListener("webkitAnimationEnd", updateClassName, true);
}
}
function updateClassName() {
var z = foo.getAttribute("class");
if ( z == "a" ) {
foo.className = "b";
} else if ( z == "b" ) {
foo.className = "c"
} else if ( z == "c" ) {
foo.className = "d"
} else {
foo.className = "a"
}
return foo;
}
Someone told me on the Javascript Chat Channel I should make a hash table for the multiple if then statements. How would I go about that?
What you would do is map
zvalues to class names, like so:The object literal is the map specifying what old value (key) should go to which new one (value). Additionally, it uses
|| "a"to specify a default case.