简体   繁体   English

如何在过渡期间暂停JavaScript执行?

[英]How to pause javascript execution during rollover?

I'm looking for a way to capture HTML of objects that are rendered on rollover. 我正在寻找一种捕获过渡时呈现的对象的HTML的方法。 An example would be: 一个例子是:

  1. Mouse over object to get popup 将鼠标悬停在对象上以弹出
  2. Press button or key to pause js (to prevent mouse out trigger) 按按钮或键暂停js(以防止鼠标移出触发器)
  3. Right click and inspect element to get HTML 右键单击并检查元素以获取HTML

Does anyone know of a way to do this? 有人知道这样做的方法吗?

To your main question, there are two ways to pause the execution of a Javascript thread: 对于您的主要问题,有两种方法可以暂停执行Javascript线程:

  1. Hit a breakpoint in a debugger 在调试器中命中断点
  2. Insert an alert() into the javascript thread and when it fires, it will suspend the execution of that javascript thread until the alert dialog is dismissed. alert()插入javascript线程,并在触发时将暂停该javascript线程的执行,直到关闭警告对话框。

You haven't described the environment you're operating in and what types of modifications you can or can't make to the host page for us to advise more specifically. 您没有描述您正在使用的环境以及您可以或不能对宿主页面进行哪些类型的修改,以便我们为您提供更具体的建议。

To approach the problem differently, to capture some dynamically inserted HTML there are other strategies. 为了解决这个问题,要捕获一些动态插入的HTML,还有其他策略。 For example, you can use your own javascript (like a bookmarklet) to attach an event handler to the mouse over. 例如,您可以使用自己的Javascript(如小书签)将事件处理程序附加到鼠标上方。 You can then set a timer that will watch for when the dynamically generated HTML seems to be present and grab a copy of it. 然后,您可以设置一个计时器,以监视似乎动态生成的HTML何时出现并获取其副本。 Keep in mind that javascript is single threaded so your own timer will only run when the other javascript thread is waiting for user input, but if the general model is that it pops something up on mouseover and then waits for additional mouse events, then this could work. 请记住,javascript是单线程的,因此您自己的计时器仅在其他javascript线程正在等待用户输入时才运行,但是如果通用模型是它在鼠标悬停时弹出某些内容,然后等待其他鼠标事件,则可能工作。

yes, <object onmouseover="functionPopup();" onmouseout="functionWrap();"> 是的, <object onmouseover="functionPopup();" onmouseout="functionWrap();"> <object onmouseover="functionPopup();" onmouseout="functionWrap();">

then place your onkeyup-event to detect the button/key. 然后放置onkeyup-event来检测按钮/键。

The trick is to leave the functionWrap on the object ALONE!!! 诀窍是将functionWrap留在对象上!!! and OVERWRITE this function functionWrap() (that is referenced by object's onmouseout) with the updated instructions (this works pretty good crossbrowser -even older ones-, since this uses the traditional event model :P ). 并使用更新的指令覆盖此函数functionWrap()(由对象的onmouseout引用)(此方法可很好地使用跨浏览器-甚至是较旧的交叉浏览器,因为它使用了传统的事件模型:P)。

Happy tweaking!! 调整愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM