我正在尝试使用 jQuery 创建一个 html 页面,并在移动设备中关闭旋转。它在我这边不起作用。
当我在移动设备上运行此 html 页面时,您能给我一些建议吗?它不应该旋转吗?
我使用了以下代码:
$(window).bind('orientationchange resize', function(event){
if (event.orientation) {
if (event.orientation == 'landscape') {
if (window.orientation == 90) {
rotate(this, -90);
} else {
rotate(this, 90);
}
}
}
});
function rotate(el, degs) {
iedegs = degs/90;
if (iedegs < 0) iedegs += 4;
transform = 'rotate('+degs+'deg)';
iefilter = 'progid:DXImageTransform.Microsoft.BasicImage(rotation='+iedegs+')';
styles = {
transform: transform,
'-webkit-transform': transform,
'-moz-transform': transform,
'-o-transform': transform,
filter: iefilter,
'-ms-filter': iefilter
};
$(window).css(styles);
};
最佳答案
下半年this回答有一个使用 json 设置 (mainfest) 文件的技巧。
简短的故事:创建一个 mainfest.json
文件:
{
"display": "standalone", /* Could be "fullscreen", "standalone", "minimal-ui", or "browser" */
"orientation": "landscape", /* Could be "landscape" or "portrait" */
...
}
然后添加到您的 HTML 页面:
<link rel="manifest" href="manifest.json">
关于javascript - 如何使用 jquery 停止移动屏幕旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30795918/