I am really new to JS/JQuery, I cant figure out how to keep this code D.R.Y, if its even possible at all I don't know. I am using JQuery for an on hover effect with an image. Box1 being the div and the img_hover_effect being the overlay on hover.
JS:
$('.box1').hover(function () {
$('.img_hover_effect').fadeIn(500);
}, function () {
$('.img_hover_effect').fadeOut(400);
});
$('.box2').hover(function () {
$('.img_hover_effect_2').fadeIn(500);
}, function () {
$('.img_hover_effect_2').fadeOut(400);
});
$('.box3').hover(function () {
$('.img_hover_effect_3').fadeIn(500);
}, function () {
$('.img_hover_effect_3').fadeOut(400);
});
You can use a loop to do that.
An anonymous function inside the loop is used to prevent breakage jQuery events, try:
Demo