我正在一個項目中,我想要顯示一個圖像,當鼠標移動到圖像上時,圖像消失,頁面上的信息出現。當鼠標移出元素時,圖像重新出現。我使用的是mouseenter和mouseleave,但如果鼠標移動得很輕微,圖像仍會閃爍。jQuery mouseenter只是閃爍的img
$(".second-div").mouseenter(function() {
$(this).removeClass("second-div");
});
$(".second-div").mouseleave(function() {
$(this).addClass("second-div");
});
.first-div {
height: 200px;
width: 300px;
border: 1px solid black;
}
.second-div {
height: 200px;
width: 300px;
border: 1px solid red;
position: relative;
bottom: 201px;
background-image: url(https://image.freepik.com/free-vector/nature-background-of-a-grassy-landscape_1048-1305.jpg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="first-div">
</div>
<div class="second-div">
</div>
這裏是的jsfiddle:
https://jsfiddle.net/cjbruin/t78v7tyj/
爲什麼沒有您的演示符合您的問題的代碼?爲什麼使用JS呢? –
可能是因爲內容不見了,所以它消失了,並導致休假... – epascarello
我更新了代碼。對不起復制了錯誤的演示。 –