【发布时间】:2015-06-14 05:49:54
【问题描述】:
我对 JS/JQuery 真的很陌生,我不知道如何保留此代码 D.R.Y,如果它甚至可能的话我都不知道。我正在使用 JQuery 来实现带有图像的悬停效果。 Box1 是 div,img_hover_effect 是悬停时的叠加层。
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);
});
【问题讨论】:
标签: javascript jquery function dry