如何在浏览器调整大小刷新屏幕? [英] How can I refresh the screen on browser resize?

查看:222
本文介绍了如何在浏览器调整大小刷新屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在浏览器大小更改时刷新页面?我使用一些样式创建页面上的区域,如果浏览器缩小布局中断。

Is it possible to refresh a page on browser size change? I use some styles that create areas on a page and if the browser is scaled down the layout break.

也许我可以用jQuery检测文档大小更改?

Perhaps I can detect the document size change with jQuery?

推荐答案

立即查看此人的任何人的更新。 JQuery现在认为bind是一个不推荐的函数。

Update for anyone viewing this now. JQuery now considers bind a deprecated function.

至于反应是如何工作的(至少在Opera / Chrome / Firefox中),它不断轮询调整大小,即使浏览器只是坐在那里。这可能是由于它是一个Drupal实现。无论哪种方式,看起来resize函数在命中location.reload()时会自动调用,导致它遇到无限循环。这是我拉在一起也解决了问题。

And the way proximus' response works (at least in Opera/Chrome/Firefox) it constantly polls for resizing even if the browser is just sitting there. This may have been due to it being a Drupal implementation. Either way, it appears that the resize function was called automatically when it hit location.reload(), causing it to hit an infinite loop. Here's what I pulled together that also solved the problem.

jQuery(function($){
var windowWidth = $(window).width();

$(window).resize(function() {
    if(windowWidth != $(window).width()){
    location.reload();
    return;
    }
});
});

这篇关于如何在浏览器调整大小刷新屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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