当鼠标悬停时,我试图在div中添加一个覆盖层。虽然它工作,覆盖一直闪烁,而我移动鼠标在div内。我怎么才能阻止这一切?
HTML:
<div id="d4" class="dmc_block" style="width:60%; background:#eee; z-index:1">
<div style="padding:20px;">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. </p>
</div>
</div>JS:
$('body').on('mouseenter','.dmc_block',function(){
var o = $(this).offset();
var h = $(this).height();
var w = $(this).width();
$('<div>').addClass('hover').css({width:w,height:h,left:o.left,top:o.top,position:'absolute',zIndex:2}).insertAfter(this);
}).on('mouseleave','.dmc_block',function(){
$('.hover').remove();
});
$('body').on('mouseenter','.hover',function(){return false;});小提琴:http://jsfiddle.net/T9Lhw/
发布于 2012-10-15 18:53:36
改变这一点:
.on('mouseleave','.dmc_block',function(){对此:
.on('mouseleave','.hover',function(){Fiddle
当覆盖.hover放置在.dmc_block之上时,它会触发mouseleave of .dmc_block,就像它现在位于.hover下面一样。你想要的是mouseleave of .hover。
https://stackoverflow.com/questions/12902088
复制相似问题