javascript - random css animation on hover -
i have javascript when hover plays animation, have 4 different animations , randomize each time element hovered over
here's code
function firsthelp() { document.getelementbyid('help-text').innerhtml = 'enter first name'; document.getelementbyid('help-box').style.animation ='greenhover 2s;'; document.getelementbyid('help-box').style.webkitanimation ='greenhover 2s'; }
the other css animations bluehover
orangehover
, purplehover
function getrandomanimation(duration) { var possibleanimations = ["greenhover","bluehover","orangehover","purplehover"]; var randomnumber = math.floor((math.random()*4)); return (possibleanimations[randomnumber] + " " + duration || ""); }
and use this:
document.getelementbyid('help-box').style.animation = getrandomanimation('2s)';