窗口传递某些多个宽度时重新加载页面 [英] Reload page when window passing certain multiple widths

查看:76
本文介绍了窗口传递某些多个宽度时重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要在浏览器窗口传递宽度为300px或769px或1024px

I need the page reload only if the browser window passing width 300px or 769px or 1024px

的情况下重新加载页面。我的请求中存在类似的问题( http://goo.gl/46jjzH )但批准答案的唯一问题是页面重新加载后只需769px,我需要同样的3个不同尺寸300px或769px或1024px而不仅仅是769px。

There is a similar question to my request (http://goo.gl/46jjzH) but the only problem with the approved answer is that the page reload after passing just 769px, I need to do the same with 3 different sizes 300px or 769px or 1024px not just 769px.

这两个代码仅适用于 http://goo.gl/46jjzH

@Roko C. Buljan的第一个代码

First code by @Roko C. Buljan

var ww = $(window).width();
var limit = 769;

function refresh() {
   ww = $(window).width();
   var w =  ww<limit ? (location.reload(true)) :  ( ww>limit ? (location.reload(true)) : ww=limit );
}

var tOut;
$(window).resize(function() {
    var resW = $(window).width();
    clearTimeout(tOut);
    if ( (ww>limit && resW<limit) || (ww<limit && resW>limit) ) {        
        tOut = setTimeout(refresh, 100);
    }
});

第二个代码@gdoron

And the second code by @gdoron

var width = $(window).width();
$(window).resize(function() {
    if (width > 769 && $(window).width() < 769) {
        location.reload();
    }
    else if (width < 769 && $(window).width() > 769) {
        location.reload();
    }
});​


推荐答案

继续第二个代码示例,您可以使用运算符检查备用条件。

Going with the second code sample, you can check for the alternate conditions using an or operator.

var prevWidth = $(window).width();
$(window).resize(function() {
    var currentWidth = $(window).width();

    if (
        (prevWidth > 769 && currentWidth  < 769) 
        || (prevWidth > 300 currentWidth  < 300)
        || (prevWidth > 1024 currentWidth  < 1024)  
    )

    {
        location.reload();
    }

});​

这篇关于窗口传递某些多个宽度时重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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