问题描述
我有 DIV网页
s的一个鼠标悬停
处理程序,旨在显示弹出信息泡沫。我不想在同一时间多个信息泡可见。但是,当用户在两个项目快速移动鼠标时,我有时会收到两个气泡。这不应该发生,因为code为显示弹出取消previous弹出。
I have a web page with DIV
s with a mouseover
handler that is intended to show a pop-up information bubble. I don't want more than one info bubble to be visible at a time. But when the user moves the mouse rapidly over two items, I sometimes get two bubbles. This should not happen, because the code for showing a pop-up cancels the previous pop-up.
如果这是一个多线程系统那么问题是显而易见的:有两个线程试图表明一个弹出窗口,他们都取消现有的弹出窗口,然后弹出自己的弹出窗口。但我以为JavaScript是始终运行单线程的,这将prevent这一点。我错了吗?在事件处理异步运行,在这种情况下,我需要共享数据同步的访问,或者我应该改为寻找库code错误取消弹出窗口?
If this were a multi-threaded system then the problem would be obvious: there are two threads trying to show a pop-up, and they both cancel existing pop-ups then pop up their own pop-ups. But I assumed JavaScript is always run single-threaded, which would prevent this. Am I wrong? Are event handlers running asynchronously, in which case I need synchronized access to shared data, or should I instead be looking for bugs in the library code for cancelling pop-ups?
编辑补充:
- 在问题库是和Ajax库;
- 事件处理程序调用
SimileAjax.DOM.cancelEvent(domEvt)
,我假设基于名称取消事件的冒泡; - 只是为了勾起回忆更为复杂,有什么我实际上做的是开始一个超时,如果不是由
moustout
取消显示弹出,这正打算prevent弹出烦人闪烁烦人,但有相反的效果。
- The library in question is SIMILE Timeline and its Ajax library;
- The event handler does call
SimileAjax.DOM.cancelEvent(domEvt)
, which I assume based on the name cancels the bubbling of events; - Just to make thing s more complicated, what I am actually doing is starting a timeout that if not cancelled by a
moustout
shows the pop-up, this being intended to prevent pop-ups flickering annoyingly but annoyingly having the reverse effect.
我不得不从另外一个戳,看看我能在哪里工作,我错了。 : - )
I'll have another poke at it and see if I can work out where I am going wrong. :-)
推荐答案
是,JavaScript是单线程的。即使是像谷歌的Chrome浏览器中,每个标签一个线程。
Yes, Javascript is single-threaded. Even with browsers like Google Chrome, there is one thread per tab.
不知道你是如何尝试取消从另一个弹出,很难说什么是你的问题的原因。
Without knowing how you are trying to cancel one pop-up from another, it's hard to say what is the cause of your problem.
如果您的DIV嵌套在彼此之内,你可能有一个<一个href=\"http://www.google.com/search?hl=en&client=firefox-a&rls=com.ubuntu:en-US:unofficial&hs=qp1&pwst=1&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=javascript+event+propagation&spell=1\"相对=nofollow>事件传播问题。
If your DIVs are nested within one another, you may have an event propagation issue.
这篇关于JavaScript是单线程?如果没有,我如何才能同步访问共享数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!