我有一個帶有嵌套在其中的兩個標籤的div,這些標籤是到其他頁面的鏈接,並且是一個緊挨着另一個頁面的鏈接。jQuery .hover()在新元素上懸停後觸發舊元素
我正在將幻燈片應用到放置在懸停標籤下的第三個div。
我遇到的問題是,如果我將鼠標懸停在其中一個標籤上,則該效果可以正常工作,然後從中移除鼠標,但不會移入下一個標籤。
如果我直接從標籤移動到另一個標籤,隱藏div的滑動效果會發生在第一個標籤上,而不是當前標籤。
HTML:
<div class="top">
<label class="head left" id="home">Welcome - <?php echo $_SESSION['description'] . " (" . $_SESSION['lid'] . ")"; ?>
</label>
<label id="logout" class="head right">Logout</label>
jQuery代碼:
// Slide in effect for hover on class=head labels
$("#home, #logout").hover(function() {
// Set width to hovering element width:
$(".labelunderscore").css("width", $(this).width() + 20);
// Set position on labelunderscore to current element left value
$(".labelunderscore").css("left", $(this).offset().left);
// Check where are we hovering. Left side slide from left right from right
if ($(this).offset().left > $(window).width()/2) {
// We are on the right side
$('.labelunderscore').show('slide', {direction: 'right'}, 200);
} else {
// Left side
$('.labelunderscore').show('slide', {direction: 'left'}, 200);
}
}).mouseout(function() {
$('.labelunderscore').hide('slide', {direction: 'left'}, 200);
})
你能否提供你的家庭和註銷html內容? –
您正在使用'in/out'懸停方式語法,當然不是您所期望的。我想你是混淆這個方法'mouseover()'一個https://api.jquery.com/hover/ ** || ** https://api.jquery.com/mouseover/ –
嗨。 Irvin我只是在尋找效果。頁面沒有準備好,並且無論如何它們都將通過.click()函數處理 –