方向更改后视口比例不起作用
我使用以下函数来重新调整 iPad 上的视口:
function rescale(scale){
var headElements = document.getElementsByTagName("meta");
for(var i = 0; i< headElements.length; i++){
var theElement = headElements[i];
if(theElement.name == "viewport"){
theElement.content = "width=device-width, user-scalable=no, initial-scale=" + scale + ", maximum-scale=" + scale + ";";
}
}
}
此功能可以无限次运行(纵向或横向),直到我更改设备的方向,此时它停止工作,直到我重新加载页面。
这是 iOS 中的一个错误,还是有任何解决方法?
I use the following function to rescale my viewport on iPad:
function rescale(scale){
var headElements = document.getElementsByTagName("meta");
for(var i = 0; i< headElements.length; i++){
var theElement = headElements[i];
if(theElement.name == "viewport"){
theElement.content = "width=device-width, user-scalable=no, initial-scale=" + scale + ", maximum-scale=" + scale + ";";
}
}
}
This works an unlimited number of times (in either portrait or landscape orientation), until I change the orientation of the device, when it ceases to work until i reload the page.
Is this a bug in iOS, or are there any workarounds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的问题,直到我开始减少参数并归结为:
我怀疑与 user-scalable=no 部分有关,因为当您更改方向时,视口宽度也会更改。但首先尝试上面的代码并从那里获取它。
我认为
maximum-scale
与方向的关系也不太好,因此在删除user-scalable
参数后尝试使用和不使用它。I had similar problems until I started cutting down on parameters and came down to this:
I suspect there's something to do with
user-scalable=no
part, since when you change orientation the viewport width is changed. But try the code above first and take it from there.I don't think
maximum-scale
plays too well with orientation either, so try with and without it after removing theuser-scalable
parameter.