admin管理员组文章数量:1291214
I have a problem with displaying my html
site on different monitors/resolutions. I was trying to to solve this problem with the following script, but it isn't working. How could I improve this?
if (width <= 1280 && height <= 720) {
document.getElementById('html').style.zoom = '50%';
html {
zoom: 100%;
}
I have a problem with displaying my html
site on different monitors/resolutions. I was trying to to solve this problem with the following script, but it isn't working. How could I improve this?
if (width <= 1280 && height <= 720) {
document.getElementById('html').style.zoom = '50%';
html {
zoom: 100%;
}
Share
Improve this question
edited Mar 27, 2015 at 13:10
shadow
22.3k5 gold badges65 silver badges79 bronze badges
asked Mar 27, 2015 at 12:39
AGOSDIZAJNAGOSDIZAJN
231 gold badge1 silver badge3 bronze badges
0
2 Answers
Reset to default 8You could scale the content without javascript, just using a mediaquery and a CSS3
transformation applied to the html
element
@media screen and (max-width: 1280px) and (max-height: 720px) {
html {
transform: scale(.5);
// or simply zoom: 50%
}
}
as a side note your code can't work because you're looking for an element with id="html"
, while you're trying to target the html
element (that is document.documentElement
or document.querySelector('html')
)
I believe this is more of a viewport and/or css media query issue. You shouldn't be trying to fix your pages look with javascript because it can be disabled. I would suggestion reading up on viewports Viewport Overview. The most monly used paired tags are:
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Those will help with resizing most of the content on the page based on the device width, other changes you'll have to manage more manually via css media queries, here is an example:
@media screen and (max-width: 300px) {
body {
width: 80%;
font-size: 15px;
}
}
The above corresponds to, at 300px or smaller change the width and font size.
I hope this helps!
本文标签: javascriptHTML full page zoom depending on screen resolutionStack Overflow
版权声明:本文标题:javascript - HTML full page zoom depending on screen resolution - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741501962a2382100.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论