在移动浏览器上设置缩放级别

发布于 2024-08-27 20:49:01 字数 184 浏览 5 评论 0原文

我正在设计用于移动访问的网站,我想设置页面宽度、高度和按钮大小,以便它们显示填满屏幕。例如,如果用户使用 HTC HD,整个屏幕将为 480x800,按钮大小为 240x200。 然而,IE 移动设备和 Opera 加载页面时具有一定的缩放级别,因此按钮显示太大或太小。如何在 javascript 中读取当前缩放级别或从 javascript 设置它?

I am designing website for mobile access and I want to set page width, height and button sizes, so they display filling up the screen. For example if user is using HTC HD , the whole screen would be 480x800 with button sized 240x200.
However IE mobile as well as Opera load the page with some zoom level, so the buttons display either too large or too small. How can I either read current zoom level in javascript or set it from javascript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残月升风 2024-09-03 20:49:01

查看 。它支持多种移动平台,包括(据我所知)iPhone、Android、Blackberry、Opera Mobile 甚至 IE6 Mobile。基本上,它可以让您预设设备宽度、缩放级别和最大/最小缩放。看看 Apple 开发者网站 并了解更多信息。

此外,您还可以使用 CSS 媒体查询来检测浏览器的形状和大小,并相应地提供不同的布局(等)。同样,这些都得到了相当广泛的支持,并且 Apple 开发者网站 有更多信息。

Take a look into <meta name="viewport">. It's supported across a wide variety of mobile platforms, including (AFAIK) iPhone, Android, Blackberry, Opera Mobile and even IE6 Mobile. Basically, it lets you preset the device width, zoom level, and max/min zoom. Have a look at the Apple developer site and for more info.

Also, you can use CSS media queries to detect the shape and size of the browser, and serve up different layouts (etc) accordingly. Again, these are fairly widely supported and the Apple developer site has more information.

煞人兵器 2024-09-03 20:49:01

您不应该依赖在移动设备上使用 JavaScript,因为它尚未在所有手机上得到广泛支持。相反,您应该将页面的宽度设置为与浏览器宽度相同,以便页面显示为 100%,例如 body {width: 100%;保证金:0; padding: 0;}

对于按钮,如果您能够在加载页面之前检测浏览器宽度,则应该使用相对值或使用不同的图像大小。

You shouldn't rely on using JavaScript on mobile devices because it is still not widely supported across all phones. Instead you should set the width of the page to be the same as the browser width so your pages appear at 100%, e.g. body {width: 100%; margin: 0; padding: 0;}

As for buttons you should use relative values or use different image sizes if you are able to detect the browser width before the page is loaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文