简体   繁体   English

载入时重置Javascript屏幕分辨率

[英]Javascript screen resolution reset on load

I am using a javascript function to reset the style of 3 DIVs based on the user screen resolution using the onload event. 我正在使用javascript函数使用onload事件根据用户屏幕分辨率重置3个DIV的样式。

if(screen.width > 1024 && screen.width < 1300){
 document.getElementById('wrapper').style.width = '1250px';
 document.getElementById('innerwrapper').style.width = '1250px';
 var elms = getElementsByClassName("colmask", "div")[0].style.width = '1250px';
}
if(screen.width > 1300 && screen.width < 1500){
 document.getElementById('wrapper').style.width = '1350px';
 document.getElementById('innerwrapper').style.width = '1350px';
 var elms = getElementsByClassName("colmask", "div")[0].style.width = '1350px';
} 
if(screen.width > 1500){
 document.getElementById('wrapper').style.width = '1580px';
 document.getElementById('innerwrapper').style.width = '1580px';
 var elms = getElementsByClassName("colmask", "div")[0].style.width = '1580px';
}

The problem is every time the user navigates to a new page the screen resizes it self after loading the page. 问题在于,每次用户导航到新页面时,屏幕都会在加载页面后自动调整其大小。 Is there a way to avoid having to resize the pages all the time ? 有没有一种方法可以避免始终调整页面大小?

I agree with the comments above and to make it dynamic based on the size of the browser is pretty easy if you decide to use Jquery 我同意上面的评论,并且如果您决定使用Jquery,根据浏览器的大小使其动态化是非常容易的

all you have to do is var wcontent=$(window).width(); 您要做的就是var wcontent=$(window).width(); and

$("#wrapper").width(wcontent);

and so on 等等

which you can place on the $(document).ready(function () {} 您可以将其放置在$(document).ready(function () {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM