我有一個像這樣的HTML,其中inner是子div,outer是父div。父小孩懸停不按預期工作
我必須達到的要求:激活那個鼠標懸停的div。
我已經調用jQuery的懸停功能,它幫助我追加和刪除活動類。
問題:當我將光標移動到innerchild div時,它會被激活,但是當我將光標從內部div移出到外部父div時,它會被激活,但外部不會被激活。
我也跟蹤了鼠標移動。 https://jsfiddle.net/Simplybj/zaz1qh8e/2/。
結果:外層div的鼠標移開時,內部的div是懸停
$('div').hover(
function() {
$('div').removeClass('activeHover');
$(this).addClass('activeHover');
},
function() {
$(this).removeClass('activeHover');
}
);
.outer {
background-color: #aeaeae;
height: 200px;
width: 200px;
float: left;
}
.inner {
margin: 50px;
background-color: #ccc;
height: 100px;
width: 100px;
float: left;
}
.activeHover {
background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<div class="outer">
<div class="inner">
</div>
</div>
如果你徘徊,你也徘徊在父母孩子...你認爲? –
是的,@Paulie_D。我有這個想法。我還嘗試解除兒童懸停時的所有懸停事件,但那也沒有奏效。我要和我的要求朋友一起去。你認爲我問不可能嗎? – mesimplybj