jQuery-实时mouseenter和mouseleave,但有例外
您好,我的代码工作正常,但我不希望在“stem”和“case”悬停在上方时触发…因为它们是动画的一部分…(它们绝对位于div#u mainGraphic上方)。有人有什么想法吗?谢谢jQuery-实时mouseenter和mouseleave,但有例外,jquery,javascript-events,Jquery,Javascript Events,您好,我的代码工作正常,但我不希望在“stem”和“case”悬停在上方时触发…因为它们是动画的一部分…(它们绝对位于div#u mainGraphic上方)。有人有什么想法吗?谢谢 $('#div_mainGraphic').live("mouseenter mouseleave", function(event){ if (event.type == 'mouseenter') { $('#stem').animate({"top": "-=35px"}, 500);
$('#div_mainGraphic').live("mouseenter mouseleave", function(event){
if (event.type == 'mouseenter') {
$('#stem').animate({"top": "-=35px"}, 500);
} else {
$('#stem').animate({"top": "+=35px"}, 150);
}
});
代码是否有效,我正在考虑这样做:
$('#div_mainGraphic').live("mouseenter mouseleave", function(event){
if (event.type == 'mouseenter') {
$('#stem').animate({"top": "-=35px"}, 500);
}
if (event.type == 'mouseleave') {
$('#stem').animate({"top": "+=35px"}, 150);
}
if (event.location == '???') {
???
}
});
以下是HTML:
<div id="div_mainGraphic">
</div>
<img src="/images/img_stem.png" id="stem" />
<img src="/images/img_case.png" id="case" />
将此操作与代码一起尝试,这将基本上停止悬停时的事件传播
$("#stem, #case").hover(function(e){
e.stopPropagation();
});
使用你的代码
$('#div_mainGraphic').live("mouseenter mouseleave", function(event){
if (event.type == 'mouseenter') {
$('#stem').animate({"top": "-=35px"}, 500);
} else {
$('#stem').animate({"top": "+=35px"}, 150);
}
});
或者,您也可以尝试将#stem和#case元素移动到#div#u mainGraphic中,因为它们是绝对定位的元素。将此与代码一起尝试,这将基本上停止悬停时的事件传播
$("#stem, #case").hover(function(e){
e.stopPropagation();
});
使用你的代码
$('#div_mainGraphic').live("mouseenter mouseleave", function(event){
if (event.type == 'mouseenter') {
$('#stem').animate({"top": "-=35px"}, 500);
} else {
$('#stem').animate({"top": "+=35px"}, 150);
}
});
或者,您也可以尝试将#stem和#case元素移动到#div#u mainGraphic中,因为它们是绝对定位的元素。我的代码中绝对简单易读的解决方案:
$('.free').live('mouseenter', function() {
$(this).find('.alert').fadeIn(200);
});
$('.free').live('mouseleave', function() {
$(this).find('.alert').fadeOut(200);
});
我的代码中绝对简单易读的解决方案:
$('.free').live('mouseenter', function() {
$(this).find('.alert').fadeIn(200);
});
$('.free').live('mouseleave', function() {
$(this).find('.alert').fadeOut(200);
});
不幸的是,这并没有做到……但这让我觉得应该是这样的。那对你有用吗?哪一个先到有关系吗?既然#stem和#case是绝对定位的元素,您可以将它们附加到#div#u mainGraphic中吗?这样,当你在鼠标上移动鼠标时,mouseenter和mouseleave仍然会触发相同的事件。你的意思是将它们移到内部还是使它们成为#div#u主图形选择器的一部分?谢谢,太好了,成功了!现在您知道关于.one()属性的任何信息吗?所以它不允许它们重叠动画?
one
用于附加任何在触发一次后自动解除绑定的事件处理程序。看看这个,不幸的是,它没有做到……但它让我觉得应该是这样的。那对你有用吗?哪一个先到有关系吗?既然#stem和#case是绝对定位的元素,您可以将它们附加到#div#u mainGraphic中吗?这样,当你在鼠标上移动鼠标时,mouseenter和mouseleave仍然会触发相同的事件。你的意思是将它们移到内部还是使它们成为#div#u主图形选择器的一部分?谢谢,太好了,成功了!现在您知道关于.one()属性的任何信息吗?所以它不允许它们重叠动画?one
用于附加任何在触发一次后自动解除绑定的事件处理程序。看看这个