i want to change an image randomly when hovering. The Hover effect is working but when the mouse moves out the image does not change back. Any ideas?
var arr = ["020", "053", "306", "035", "930"];
function getRandomImage() {
var index = Math.floor(Math.random() * arr.length);
return arr[index];
}
$(function(){
$(".size-woocommerce_thumbnail").hover(function(){
var image = getRandomImage();
$(this).attr("srcset", function(index, attr){
return attr.replace("070", image);
});
$(this).attr("src", function(index, attr){
return attr.replace("070", image);
});
}, function(){
$(this).attr("srcset", function(index, attr){
return attr.replace(image, "070");
});
$(this).attr("src", function(index, attr){
return attr.replace(image, "070");
});
});
});
Aucun commentaire:
Enregistrer un commentaire