开发者

Stop a function, if another is running

开发者 https://www.devze.com 2023-02-10 06:47 出处:网络
I have two events on an form input: onMouseOver and onMouseOut. The functions that these events run, effect the came content, and each function takes about 2 seconds to complete all the code. Therefor

I have two events on an form input: onMouseOver and onMouseOut. The functions that these events run, effect the came content, and each function takes about 2 seconds to complete all the code. Therefore, how do I fix this scenario: If I was to fire the onmouseover event then onmouseout, but befor开发者_运维百科e the code can complete for the onmouseout I fire the onmouseover event. When I try this screws up all the code, so how do I fix this?


You can't stop one function with another. Javascript events are handled in order one at a time, if your onmouseout triggers while onmouseover is still busy, it'll be queued and run when onmouseover is finished.

Honestly, onmouseanything events shouldn't take more than a fraction of a second to complete. You need to restructure your app to do less for these events.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号