$tbody.find('.heartF').each(function() {
$(this).hover(
function() { $(this).hide(); },
function() { $(this).show(); }
);
});
滑鼠移入圖片區域時,圖片快速閃爍而非穩定隱藏。
事件綁定在圖片本身。當 mouseenter 觸發 hide(),圖片消失導致滑鼠不再位於該元素上,立即觸發 mouseleave 執行 show(),圖片再次出現 → 觸發 mouseenter → 無限循環閃爍。
<div> 或 <span>)。hover 綁定在容器上,操作內部圖片顯示/隱藏。width/height 或 display:inline-block 保持佈局不塌陷。<!-- HTML 結構 -->
<div class="heart-container" style="width:32px;height:32px;display:inline-block;">
<img class="heartF" src="heart.png" alt="" style="display:block;" />
</div>
<!-- jQuery -->
$('.heart-container').hover(
function() { $(this).find('.heartF').hide(); },
function() { $(this).find('.heartF').show(); }
);
.heart-container:hover .heartF { display: none; }
純 CSS 解決方案效能最佳、無閃爍、無需 JS 綁定。
:hover、:focus、:active。opacity + visibility 或 transform,而非 display 切換。