How do I avoid massive onmouseover onmouseout firing?

前端 未结 5 1258
轻奢々
轻奢々 2021-01-06 19:55

I have a table with some columns. In each of them is a picture where I have an onmouseover/onmouseout event on it, which shows a message in a div and hides the message.

5条回答
  •  自闭症患者
    2021-01-06 20:39

    You can't, and shouldn't try to, avoid the events firing. What you should avoid is your code immediately responding to them by doing something that winds up looking stupid. For example, you can have your mouseovers register, with some controller object, which image the user is currently over, and set a short timeout to the function that triggers the actual behavior (removing a previous timeout if it's already running). The mouseout unregisters the image and removes the timeout. That way, when the behavior runs, you only operate on the image that the user moused over most recently.

提交回复
热议问题