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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The following should work:
var resizeEvent = new Event('resize');
window.dispatchEvent(resizeEvent);
Simple (ridiculously so) demo.
References:
- Creating and triggering (JavaScript) events.
Event()
constructor.