Javascript 屏幕分辨率在加载时重置
我正在使用 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';
}
问题是每次用户导航到新页面时,屏幕都会在加载页面后自行调整大小。有没有办法避免一直调整页面大小?
I am using a javascript function to reset the style of 3 DIVs based on the user screen resolution using the onload event.
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我同意上面的评论,如果您决定使用 Jquery,那么根据浏览器的大小使其动态化是非常容易的,
您所要做的就是
var wcontent=$(window).width();
等等
,
您可以将其放在
$(document).ready(function () {}
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
all you have to do is
var wcontent=$(window).width();
and
and so on
which you can place on the
$(document).ready(function () {}