如何设置仅适用于 iPhone 或 iPad 的视口?
我有一个网站,需要在 iphone 上使用 0.3 的视口值,但在 ipad 上使用 0.7。
有没有办法只为 iPhone 或 iPad 设置视口?
I have a website that needs to use 0.3 value for viewport on iphone, but 0.7 for ipad.
Is there a way to set viewport for only iphone or ipad?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这是一种解决方案...
Here is one solution...
我用 jQuery 找到了一个简单的方法!
将其添加到
标记:
标记设置默认比例,
标记重新设置如果设备屏幕宽度小于 600 像素(我认为所有手机设备都在 600 像素以下),则写入视口。
我在任何地方都找不到简单的解决方案,所以我想出了这个:)
I found a simple way with jQuery!
Add this to the
<head>
tag:The
<meta>
tag sets the default scale and the<script>
tag re-writes the viewport if the device screen width is less than 600 pixels (I think all phone devices are under 600px).I could not find a simple solution anywhere so I came up with this :)
请注意,
meta viewport
是逗号分隔的列表,不应使用分号。来源:
Apple 文档中的视口语法 和
配置视口 - Apple 文章
(如果我有更多声誉点,我会将其添加为评论)
Please note,
meta viewport
is comma-delimited list, you should not use semicolons.Source:
viewport syntax in Apple's documentation and
Configuring the Viewport – Apple article
(If I had more reputation points, I would add this as a comment)
对于所有移动设备,请尝试这样的操作。
For all mobile devices, try something like this.
这有效,但只有之后我意识到这一行不会进入...部分!我很愚蠢,但也许需要说一下。
谢谢!
This worked but only after I realized that this line does not go in the ... section! Dumb of me, but maybe needs to be said.
Thanks!
Tim 使用 jquery 的脚本似乎运行良好。我稍微改变了它,它似乎对我有用。我添加了一些比例参数。它为我提供了我的页面在 iPhone 和 iPad 上良好显示所需的结果。这是我添加的内容:
That script from Tim that uses jquery seems to work well. I changed it a little bit and it seems to work for me. I added some scale parameters. It gave me the results I needed for my page display well on both iphone and ipad. Here is what I added:
我不确定你可以只为 iPhone 设置视口,但你可以设置媒体查询,因此我认为只为 iPhone 设置 CSS。
通过仅针对 iPhone (320x480) 或 iPad (1024x768) 的设备宽度设置媒体查询,您可能会实现您想要的效果。
I'm not sure you can set a viewport for only iPhone but you could set the media query and thus the CSS for only iPhone I think.
By setting the media query for only device widths of the iPhone (320x480) or iPad (1024x768) you could possibly achieve what you're trying for.
请参阅下面我的答案,了解如何动态设置初始缩放,以便整个网站在页面加载时正确缩放(适用于所有设备尺寸)。
更改平板电脑视口以准确显示固定尺寸元素< /a>
See my answer below on how to dynamically set your initial-zoom so that your entire site is zoomed correctly on page load (works for all device sizes).
Change tablet viewport to exactly show fixed dimension element