问题描述
我正在寻找一个javascript来根据viwewers屏幕分辨率更改网站的缩放。我用1920x1080p在我的桌面上制作了网站:/
I'm looking for a javascript to change the zoom of the website depending on the viwewers screen resolution. I made the website on my desktop with 1920x1080p :/
html { -moz-transform: scale(0.75, 0.75); zoom: 0.75; zoom: 75%; }
我在我的css中得到了这个,以便将网站缩放到我喜欢的MacBook(1280 x 800) 。
I got this in my css to zoom the website to my liking for MacBook (1280 x 800).
但是我不知道如何使用javascript启用/禁用它(如果可能的话?)以及如何检测分辨率。
However I have no idea how to enable/disable it using javascript (if its possible?) and how to detect the resolution.
任何帮助都是适当的! :)
Any help is appriciated! :)
推荐答案
css @media查询会帮助你,不需要javascript.for示例
css @media queries will help you,don't need javascript.for example
@media screen and (max-width: 1280px) {
html {
-moz-transform: scale(0.75, 0.75);
zoom: 0.75;
zoom: 75%;
}
}
@media screen and (max-width: 800px) {
html {
-moz-transform: scale(0.50, 0.50);
zoom: 0.50;
zoom: 50%;
}
}
如果你特别想要javascript然后看看窗口对象
if you specifically want javascript then look at window screen object w3schools
<script>alert("Screen Width: " + screen.width);</script>
这篇关于根据显示器分辨率缩放网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!