Skip to content

Instantly share code, notes, and snippets.

@shortcircuit3
Created November 28, 2012 13:43
Show Gist options
  • Save shortcircuit3/4161382 to your computer and use it in GitHub Desktop.
Save shortcircuit3/4161382 to your computer and use it in GitHub Desktop.
Randomize string on hover
var random_interval = 0;
var textArray = ['home','office','school','hotel','gym','daycare', "doctor's office"];
$(".random").hover(
function () {
random_interval = setInterval(function(){
var randomIndex = Math.floor(Math.random() * textArray.length);
var randomElement = textArray[randomIndex];
$('.random').text(randomElement);
}, 300);
},
function () {
clearInterval(random_interval);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment