强制窗口调整大小以触发 [英] Forcing windows resize to fire
问题描述
我的布局有问题,当我手动调整窗口大小并将其恢复正常时,一切都在完美的位置。
I have problems with my layout, when I re-size window manually and restore it to normal everything is in the perfect place.
是否有可能欺骗浏览器并使用JavaScript做一些实际上会让浏览器认为页面已经重新调整大小以便我的布局看起来应该如此?
Is it possible to trick the browser and do something with JavaScript that would actually make the browser think that the page has been re-sized so that my layout looks as it should?
更新:
我可以重新调整大小和恢复窗口以便用户几乎没有注意到?
Can I re-size and restore window so that user barely notices?
推荐答案
这可以通过 Mootools (这意味着它可以在没有框架的情况下完成),这是一个例子:
This is possible with Mootools (which means it can be done without a framework as well), here's an example:
window.addEvent('domready', function() {
window.addEvent('resize', function() {
alert('f');
});
(function() {
window.fireEvent('resize');
}).delay(3000);
});
加载DOM结构3秒后,将为窗口触发resize-event-对象。
3 seconds after the DOM-structure has loaded, the resize-event will be fired for the window-object.
编辑;
我不知道Mootools如何解决他们的fireEvent用于调整大小事件。我试过谷歌,但发现了虚无...您当然可以手动调整窗口大小,但这实际上是一个黑客:
I have no clue how Mootools solves their fireEvent for the resize event. I tried Google, but found nada. You can of course resize the window manually, but this is really a hack:
function fireOnResizeEvent() {
var width, height;
if (navigator.appName.indexOf("Microsoft") != -1) {
width = document.body.offsetWidth;
height = document.body.offsetHeight;
} else {
width = window.outerWidth;
height = window.outerHeight;
}
window.resizeTo(width - 1, height);
window.resizeTo(width + 1, height);
}
window.onresize = function() {
alert("Resized!");
}
这篇关于强制窗口调整大小以触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!