求助,重力感应代码问题

html-css012

求助,重力感应代码问题,第1张

下面这个方法可以判断是横屏还是竖屏,但是似乎并不能强制更改window.orientation的值来实现旋转屏幕。

function orient() {if (window.orientation == 0 || window.orientation == 180) {

alert('竖屏')

$("body").attr("class", "portrait")

orientation = 'portrait' return false

}else if (window.orientation == 90 || window.orientation == -90) {

alert('横屏')

$("body").attr("class", "landscape")

orientation = 'landscape' return false

}

}

$(window).bind( 'orientationchange', function(e){

orient()

})

$(function(){

orient()

})

如果页面元素比较简单的话,或许可以尝试使用CSS3旋转90度来实现伪横屏,不过一般效果都不大好。

body{-webkit-transform:rotate(90deg) transform:rotate(90deg)

}

88%/1.4

88% 为字体大小,这个字体大小是相对于父级字体的大小,如,如果父级的大小为

14px 那么这里的大小就为:14*88% 这个大小

后面的 1.4 为1.4倍的行高。

以上……