当您将鼠标悬停在我的图像上时,会出现一个按钮。问题是,当用户尝试单击按钮时,它开始闪烁,用户现在已关闭 <img>
标签。我无法放置 jQuery hover()
选择器来检测用户何时将鼠标悬停在我的整个元素上,因为我在图像下有文本,并且我不希望当用户将鼠标悬停在文本上时出现该按钮。我如何获得 <button>
当用户尝试单击它时不闪烁。
<div class="item">
<img src="http://www.placehold.it/250x100">
<button>More Info</button>
<p>Description</p>
</div>
button { position:absolute; top:20px; left:90px; display:none; }
$('.item img').hover( function() {
$(this).parent().find('button').show();
}, function() {
$(this).parent().find('button').hide();
}
);
最佳答案
将悬停效果应用于图像和按钮:
$('.item img, .item button').hover( function() {
$(this).parent().find('button').show();
}, function() {
$(this).parent().find('button').hide();
}
);
关于jquery - 防止悬停时按钮闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13533680/