模拟事件调整大小 [英] Simulate event resize
本文介绍了模拟事件调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用DOM2,并使用 addEventListener
为 window
对象添加了一些事件侦听器调整大小 。现在,我需要模拟此操作(window.resize),以调用附加到 window
对象的事件侦听器。我该怎么办?
Hi I'm using DOM2 and added a few event listeners "resize" for window
object, using addEventListener
. And now I need to simulate this action (window.resize) to call event listeners that are attached to the window
object. How can I do it?
推荐答案
以下方法应该起作用:
var resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
参考文献:
- Creating and triggering (JavaScript) events.
Event()
constructor.
这篇关于模拟事件调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文