I have this code to add a class from a list when the mouse is over a button, and it works, but every time the mouse touches the button a new class is added from the list. I need it just add one class.
var classes = ["fadeOutRight","fadeOutLeft","fadeOutDown","fadeOutUp","zoomOutLeft","zoomOutRight","zoomOutDown","zoomOutUp"];
$(".work").mouseover(function() {
$(".paj").each(function(){
$(this).addClass(classes[~~(Math.random()*classes.length)]);
});
});
I tried this but is not working:
var classes = ["fadeOutRight","fadeOutLeft","fadeOutDown","fadeOutUp","zoomOutLeft","zoomOutRight","zoomOutDown","zoomOutUp"];
$(".work").mouseover(function() {
if(!$(this).hasClass(classes)){
$(".paj").each(function(){
$(this).addClass(classes[~~(Math.random()*classes.length)]);
});
};
});
Also, I need when the mouse is out it deletes all classes from the list. I tried this but it does not work either:
$(".work").mouseout(function() {
$(".paj").removeClass(classes);
});