鼠标悬停和鼠标移出功能 jQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5166776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mouseover and Mouseout function jQuery
提问by Mike
I have this script:
我有这个脚本:
$("#teaser ul.buttons li").mouseover(function()
{
$("a",this).animate({ left: '0' },350);
}).mouseout(function()
{
$("a",this).animate({ left: '-11px' },350);
});
But when i now hover over the a element. The mouseover and mouseout going continu. How can i change this script. That when i hover of the a element. That the mouseout launch when i hover off the element.
但是当我现在将鼠标悬停在 a 元素上时。mouseover 和 mouseout 继续。我该如何更改此脚本。当我悬停在 a 元素上时。当我将鼠标悬停在元素上时,mouseout 会启动。
回答by Rafay
use mouseenter
and mouseleave
instead of mouseover
and mouseout
使用mouseenter
andmouseleave
代替mouseover
andmouseout
回答by andyb
Is http://jsfiddle.net/BBUJ7/what you are looking for? I changed the mouseover
and mouseout
to hoversince you mentioned hovering in the question and added a {position:relative}
CSS rule.
是http://jsfiddle.net/BBUJ7/你在找什么?自从您提到在问题中悬停并添加CSS 规则后,我将mouseover
和更改mouseout
为悬停a {position:relative}
。
回答by Mike
Here you have html code:
在这里你有 html 代码:
<ul class="buttons">
<li>
<h2>
<a class="koeriersdiensten" href="pagina.html" title="Koeriersdiensten">Koeriersdiensten
<span>Lorem ipsum dolor sit amet</span>
</a>
</h2>
</li>
<li>
<h2>
<a class="taxivervoer" href="pagina.html" title="Taxivervoer">Taxivervoer
<span>Lorem ipsum dolor sit amet</span>
</a>
</h2>
</li>
</ul>