I came across this post (http://stackoverflow.com/questions/10665918/jquery-animate-shake-on-hover) which is almost what I'm looking for, and this jsfiddle (http://jsfiddle.net/g6AeL/222/), but I just need the vibrate function to happen once when you hover on the item instead of continuously vibrating while you're hovering over the item.
Could someone help me with making it just do it once when you hover over the item?
Here's the javascript from the jsfiddle.
$(function() {
var interval = 10;
var duration= 1000;
var shake= 3;
var vibrateIndex = 0;
var selector = $('.box'); /* Your own container ID*/
$(selector).each(function(){
var elem = this;
$(this).hover( /* The button ID */
function(){
vibrateIndex = setInterval(function(){
vibrate(elem);
}, interval);
},
function(){
clearInterval(vibrateIndex);
$(this).stop(true,false)
.css({position: 'static', left: '0px', top: '0px'});
}
);
})
var vibrate = function(elem){
$(elem).stop(true,false)
.css({position: 'relative',
left: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px',
top: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px'
});
}
});