Javascript 如何使用jquery停止移动屏幕旋转?

Javascript 如何使用jquery停止移动屏幕旋转?,javascript,jquery,html,jquery-mobile,Javascript,Jquery,Html,Jquery Mobile,我正在尝试使用jQuery创建一个html页面,并在mobile中关闭旋转。这在我这边不起作用 你能不能给我一些建议,当我在手机上运行这个html页面时,它不应该被旋转 我使用了以下代码: $(window).bind('orientationchange resize', function(event){ if (event.orientation) { if (event.orientation == 'landscape') { if (window.orientatio

我正在尝试使用jQuery创建一个html页面,并在mobile中关闭旋转。这在我这边不起作用

你能不能给我一些建议,当我在手机上运行这个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);
 };
$(窗口).bind('orientationchange resize',函数(事件){
if(事件方向){
如果(event.orientation==“横向”){
如果(window.orientation==90){
旋转(此为-90);
}否则{
旋转(这个,90);
}
}
}
});
功能旋转(el、degs){
iedegs=degs/90;
如果(iedegs<0)iedegs+=4;
变换='旋转('+degs+'deg');
iefilter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+iedegs+');
样式={
变换:变换,
“-webkit转换”:转换,
“-moz变换”:变换,
“-o-变换”:变换,
过滤器:iefilter,
“-ms过滤器”:iefilter
};
$(窗口).css(样式);
};
在答案的后半部分,有一个使用json设置(mainfest)文件的技巧

简短的故事:创建一个
mainfest.json
文件:

 {
     "display":      "standalone", /* Could be "fullscreen", "standalone", "minimal-ui", or "browser" */
     "orientation":  "landscape", /* Could be "landscape" or "portrait" */
     ...
 }
然后添加到您的HTML页面:



事实上,我正在创建一个页面,该页面必须以肖像形式显示。当用户使用自然比身高宽的设备查看该页面时,您预计会发生什么情况?平板电脑,手机,等等?看起来不太好。我只想画一幅肖像画。当用户试图将其移动到横向位置时,据我所知,它不应该被移动,它不能以这种方式工作。!由于技术限制,javascript/Jquery无法控制设备方向。如果它是一个应用程序,那么它是可能的。!但你可以尝试在用户改变手机方向时发出警告信息。例如,查看此银行移动网站。
 <link rel="manifest" href="manifest.json">