Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

javascript - 跨浏览器窗口调整大小事件 - JavaScript / jQuery(Cross-browser window resize event - JavaScript / jQuery)

What is the correct (modern) method for tapping into the window resize event that works in Firefox, WebKit , and Internet Explorer?(在Firefox, WebKit和Internet Explorer中使用的窗口调整大小事件的正确(现代)方法是什么?)

And can you turn both scrollbars on/off?(你可以打开/关闭两个滚动条吗?)

  ask by BuddyJoe translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

jQuery has a built-in method for this:(jQuery有一个内置的方法 :)

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

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 :(对于用户界面的响应起见,你可以考虑使用的setTimeout只有经过数毫秒打电话给你的代码,如下面的例子,启发这样 :)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...