Javascript 在移动设备上保持网站处于横向模式
有没有办法在移动设备上保持移动网站处于横向模式Javascript 在移动设备上保持网站处于横向模式,javascript,jquery,ajax,mobile,Javascript,Jquery,Ajax,Mobile,有没有办法在移动设备上保持移动网站处于横向模式 我们可以使用任何JavaScript代码吗?限制用户可能会破坏用户体验,如果您确信这不会破坏体验,请继续使用此代码---> //此函数将旋转屏幕(跨浏览器!!!) 功能旋转(el、degs){ iedegs=degs/90; 如果(iedegs
我们可以使用任何JavaScript代码吗?限制用户可能会破坏用户体验,如果您确信这不会破坏体验,请继续使用此代码--->
//此函数将旋转屏幕(跨浏览器!!!)
功能旋转(el、degs){
iedegs=degs/90;
如果(iedegs<0)iedegs+=4);
变换='旋转('+degs+'deg');
iefilter='progid:DXImageTransform.Microsoft.BasicImage(rotation='+iedegs+');
样式={
变换:变换,
“-webkit转换”:转换,
“-moz变换”:变换,
“-o-变换”:变换,
过滤器:iefilter,
“-ms过滤器”:iefilter
};
$(el).css(样式);
}
//这将检查你的方位,然后在你下钻时采取行动!!!
$(窗口).bind('orientationchange resize',函数(事件){
if(事件方向){
如果(event.orientation==“横向”){
如果(window.rotation==90){
旋转(此为-90);
}否则{
旋转(这个,90);
}
}
});
按照问题的顺序,是和否,这一行显示错误,如果(iedegs<0)iedegs+=4);
暂时扔掉ie的东西…然后重新检查!!!大多数人喜欢ie以外的web浏览器,如果你获得了正确的功能,回头看看一些ie解决方案…但我认为它应该可以工作!!!
//this function will rotate you screen(cross browser!!!)
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
};
$(el).css(styles);
}
//this will check your orientation and then take action as you desrired!!!
$(window).bind('orientationchange resize', function(event){
if(event.orientation) {
if (event.orientation == 'landscape') {
if (window.rotation == 90) {
rotate(this, -90);
} else {
rotate(this, 90);
}
}
});