[英]Disable hover event on parent when mouse is over specific children elements
我想創建一個Slider,其效果是當光標到達#sliderarea
(兩個部分之間的區域)時, #slidertop
和#sliderbottom
將消失。
演示 : http : //codepen.io/anon/pen/vEdPxR
這確實有效,但效果從早期開始!
只要光標位於#slidertop
和#sliderbottom
部分上, #slidertop
和#sliderbottom
應該移動。
我認為.unbind()
函數可能是一個解決方案,但我不知道它是否適用於我的代碼。
我想要的 :
#slidertop
& #sliderbottom
- >無效 #sliderarea
- >效果開始 - > #slidertop
& #sliderbottom
消失 #sliderarea
- > #slidertop
& #sliderbottom
出現 非常感謝!
更改
$('#sliderarea').hoverIntent(getSmalls, getTalls);
成
$('#slidertop, #sliderbottom').hoverIntent(getSmalls, getTalls);
問題是, #slidertop
和#slidertop
是#sliderarea
元素的一部分。 因此,在此元素上偵聽hover
事件時,您實際上正在偵聽hover
在其所有內容上,包括#slidertop
和#slidertop
。
您可以在#sliderarea
( #slidertop
和#slidertop
divs下方)中添加另一個<div>
,並將您的內容放在那里。 然后在該元素上偵聽hover
事件,而不是整個sliderarea
。
HTML:
<div class="container">
<div id="sliderarea">
<div id="slidertop"></div>
<div id="sliderbottom"></div>
<div id="slidercontent">... Your content here ...</div>
</div>
</div>
添加CSS:
#slidercontent {
height : 250px; /* same as for the #sliderarea */
max-width : 800px; /* same as for the #sliderarea */
}
腳本:
$(document).ready(function(){
// listen for hover event on #slidercontent:
$('#slidercontent').hoverIntent(getSmalls, getTalls);
});
// unchanged part of your code:
function getSmalls(){
$('#slidertop').animate({"height": 0}, 200);
$('#sliderbottom').animate({"height": 0}, 200);
}
function getTalls(){
$('#slidertop').animate({"height": 50}, 200);
$('#sliderbottom').animate({"height": 50}, 200);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.