DOM onresize事件 [英] DOM onresize event

查看:343
本文介绍了DOM onresize事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这个

window.onresize = function() {
  alert('resized!!');
};

我的函数在整个调整大小中被多次触发,但是我想捕获调整大小的完成。这是在IE中。

My function gets fired multiple times throughout the resize, but I want to capture the completion of the resize. This is in IE.

任何想法?有很多的想法,但目前还没有为我工作(例如IE的所谓window.onresizeend事件。)

Any ideas? There are various ideas out there, but not has worked for me so far (example IE's supposed window.onresizeend event.)

推荐答案

在这种情况下,我会强烈地建议去抖动。我发现的最简单,有效和可靠的JavaScript方法是 Ben Alman的jQuery插件,Throttle / Debounce (可以使用或不使用jQuery - 我知道...听起来很奇怪)。

In this case, I would strongly suggest debouncing. The most simple, effective, and reliable way to do this in JavaScript that I've found is Ben Alman's jQuery plugin, Throttle/Debounce (can be used with or without jQuery - I know... sounds odd).

使用去抖动,代码要做到这一点,可以这样简单:

With debouncing, the code to do this would be as simple as:

$(window).resize($.debounce(1000, function() {
   // Handle your resize only once total, after a one second calm.
   ...
}));

希望能帮助某人。 ;)

Hope that can help someone. ;)

这篇关于DOM onresize事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆