我正在尝试使用单独的元视点数据为 iPad 和 iPhone 调整网站大小。
到目前为止,这是我正在使用的:
<meta id="viewport" name='viewport'>
<script>
(function(doc) {
var viewport = document.getElementById('viewport');
if ( navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
doc.getElementById("viewport").setAttribute("content", "initial-scale=0.3");
} else if ( navigator.userAgent.match(/iPad/i) ) {
doc.getElementById("viewport").setAttribute("content", "initial-scale=0.7");
}
}(document));
</script>
而且它工作得很好。唯一的问题是当设备也是纵向/横向时,我需要不同的比例。
有什么想法吗?
谢谢
最佳答案
看看 CSS definition of a media query.
@media screen and (orientation:portrait) { … }
@media screen and (orientation:landscape) { … }
例如,您可以根据可以设置缩放比例的方向使用不同的样式表:
<link rel=”stylesheet” media=”all and (orientation:portrait)” href=”css/portrait.css”>
<link rel=”stylesheet” media=”all and (orientation:landscape)” href=”css/landscape.css”>
关于javascript - iPhone/iPad 视角在纵向和横向上发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18915079/