有没有办法让移动网站在移动设备上保持横向模式?
我们可以使用任何 JavaScript 代码来实现吗?
限制用户可能会破坏用户经验,如果您确定它不会破坏体验,请继续使用此代码--->
//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);
}
}
});