jQuery:如何触发悬停?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10636581/
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
jQuery: how to trigger hover out?
提问by Alex G
How can I trigger second hover function?
如何触发第二次悬停功能?
$('#adm1n-toolbar').hover(
function() {
...
},
function() {
...
}
);
$('#adm1n-toolbar-content select').change(function(e) {
...
$('#adm1n-toolbar').trigger('mouseout');
});
mouseout or mouseleave does not work.
mouseout 或 mouseleave 不起作用。
回答by Gabriele Petrioli
It works just fine if you use mouseleave
which is what hover
uses behind the scenes
如果您使用mouseleave
which 是hover
在幕后使用的,它就可以正常工作
demo at http://jsfiddle.net/gaby/6fyeS/
回答by Rory McCrossan
You can't externally target the second function in hover()
. However as hover()
is just a shortcut for mouseenter()
and mouseleave()
you can assign them separately to let you trigger them as you need. Try this:
您不能将hover()
. 但是 ashover()
只是一个快捷方式mouseenter()
,mouseleave()
您可以单独分配它们,以便您根据需要触发它们。尝试这个:
$('#adm1n-toolbar')
.mouseenter(function() {
// ...
})
.mouseleave(function() {
// ...
});
$('#adm1n-toolbar-content select').change(function(e) {
$('#adm1n-toolbar').trigger('mouseleave');
});