有没有办法降低 onMouseLeave 或 onMouseOut 触发事件的灵敏度。因为我想将它们应用于弹出对话框,除非它们在鼠标悬停在文本(即 div 标签)上时一直在触发,只有当我完全冷静下来时它们才不会触发并且弹出对话框还可以.功能显然有效,但鼠标事件的敏感性太高。
这是我最重要的代码部分:
<div className="titleUnderLogo">
<br /> <br />
{applicationDataDefinition.map((item) =>
<div className="titleUnderLogo" onMouseOver = {this.mouseOver} onMouseLeave={this.mouseLeave} /* Tried with this also onMouseOut={this.mouseOut} */ >
{item.name} {item.release} - {item.level} - {item.location}
</div>
)}
<br /> <br />
<Container >
<Dialog
displayed = {showDialog}
title="Product name"
modal={true}
layout="center"
defaultFocus="#ok"
ui="titleUnderLogoCls"
closeAction="hide"
maskTapHandler={this.mouseTapped}
onHide={() => this.setState({ showDialog: false })}
>
{applicationDataDefinition.map((item) =>
<div>
<table>
<tr>
<td> <b> Product name: </b> </td>
<td> {item.name} </td>
</tr>
<tr>
<td> <b> Release: </b> </td>
<td> {item.release} </td>
</tr>
<tr>
<td> <b> Last fix installed: </b> </td>
<td> {item.lastFix} </td>
</tr>
<tr>
<td> <b> Environment: </b> </td>
<td> {item.level} </td>
</tr>
<td> <b> Location: </b> </td>
<td> {item.location} </td>
</table>
</div>
)}
</Dialog>
</Container>
</div>
最佳答案
您可以使用 lodash.throttle 限制事件
element.addEventListener('mouseout', _.throttle(callback, 100)); // 100 miliseconds
callback
是你在 mouseout 上做的函数编辑
好吧,我不明白 react ,但正如我所见,一定是这样的
this.mouseOver
//似乎是您的 ViewModel 中的一个方法,所以mouseOver: _.throttle(() => {
// do something here or call another function like
this.yourFunctionFromViewModelForMouseOver();
},100)
onMouseLeave={this.mouseLeave}
也一样mouseLeave: _.throttle(() => {
// do something here or call another function like
this.yourFunctionFromViewModelForMouseLeave();
},100)
关于javascript - onMouseLeave 和 onMouseOut 激活太快;,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50715539/