我有这个小悬停脚本。
$('iframe').hover(function() {
$('.caption').fadeIn(800);
},
function() {
$('.caption').fadeOut(800);
});
当我将鼠标悬停在 iframe 上时,它会在“标题”类中淡出。当我退出悬停时,它会淡出。够简单的。
我正在使用一个插件,该插件将“当前”类添加到当前 View 中的面板。我如何添加到此代码中,以便仅当面板具有“当前”类时才会发生此效果。
谢谢!
最佳答案
您可以使用jQuery is method像这样:
$('iframe').hover(function() {
if ($(this).is('.current')) {
$('.caption').fadeIn(800);
}
},
function() {
if ($(this).is('.current')) {
$('.caption').fadeOut(800);
}
});
或者,如果您只想定位 .caption
元素,这些元素是 .current
的后代(如果 iframe 不是具有当前 css 的“面板”)类):
$('iframe').hover(function() {
$('.current').find('.caption').fadeIn(800);
},
function() {
$('.current').find('.caption').fadeOut(800);
});
关于jquery - 如果类是 'current' ,则执行此操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9035252/