跨浏览器窗口调整大小事件 - JavaScript / jQuery [英] Cross-browser window resize event - JavaScript / jQuery

查看:92
本文介绍了跨浏览器窗口调整大小事件 - JavaScript / jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是正确的(现代)方法,用于点击在Firefox中可用的窗口调整大小事件, WebKit 和Internet Explorer?

What is the correct (modern) method for tapping into the window resize event that works in Firefox, WebKit, and Internet Explorer?

您可以打开/关闭这两个滚动条吗?

And can you turn both scrollbars on/off?

推荐答案

jQuery对此有内置方法

jQuery has a built-in method for this:

$(window).resize(function () { /* do something */ });

为了UI响应,你可以考虑使用setTimeout来调用你的代码。的毫秒数,如以下示例所示,受到

For the sake of UI responsiveness, you might consider using a setTimeout to call your code only after some number of milliseconds, as shown in the following example, inspired by this:

function doSomething() {
    alert("I'm done resizing for the moment");
};

var resizeTimer;
$(window).resize(function() {
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout(doSomething, 100);
});

这篇关于跨浏览器窗口调整大小事件 - JavaScript / jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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