您可以向“活动”标题添加一个类,而不是取消绑定悬停动作,然后在悬停动作中检查它:
$('.pic').hover(function() {
var caption = $(".caption",this);
if ( ! caption.hasClass("active") ) {
caption.stop().fadeIn();
}
},
function() {
var caption = $(".caption",this);
if ( ! caption.hasClass("active") ) {
caption.stop().fadeOut();
}
});
$('.pic').click(function() {
//fade out all other captions that have kept their hover states/ This wasn't the first pic clicked on
$('.caption').fadeOut().removeClass("active");
//fade in only this caption when clicked
$(".caption", this).fadeIn().addClass("active");
});
示例:http:
//jsfiddle.net/bstakes/62cRZ/9/