typescript div 和 childs 上的 Angular 2 鼠标悬停事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39767987/
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
Angular 2 mouseover event on div and childs
提问by Gerald Hughes
I have a span child in a div.
我在一个 div 中有一个跨度孩子。
On my div I have a mouseover
event, when I hover on the span
, my event triggers.
在我的 div 上,我有一个mouseover
事件,当我将鼠标悬停在 上时span
,我的事件就会触发。
Simple code:
简单代码:
<div (mouseover)="showOverlay($event, FooBar)" (mouseleave)="showOverlay($event, FooBar)">
<span>{{ someDataHere }}</span>
</div>
public showOverlay($event, op, element): void {
op.toggle($event, element);
$event.preventDefault();
}
What I want is to keep showing my overlay when on child, how do I achieve this?
我想要的是在孩子身上继续显示我的叠加层,我该如何实现?
回答by Günter Z?chbauer
mouseenter
and mouseleave
cover this use case better because entering a child doesn't mouseleave
to fire, only leaving the outside border of the actual element makes it to fire.
mouseenter
并mouseleave
更好地覆盖这个用例,因为进入一个孩子不会mouseleave
触发,只有离开实际元素的外边界才能触发。
See also What is the difference between the mouseover and mouseenter events?