所以我发现了一些关于在安卓设备上检查oreintation的方便代码,这些代码对于加载基于设备旋转的样式表非常有效,但我现在的问题是,如果设备已经是“横向的”(JS中的90 / -90),那么它就会忽略下面代码中的规则,所以我需要下面的代码来在onload上运行,我已经尝试过了,但似乎就是做不对。
帮帮忙好吗?
//detect orientation change
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
if(window.orientation == 90) {
$('link[title=android]')[0].disabled=true;
$("head").append($("<link title='android_90' rel='stylesheet' href='css/android_90.css' type='text/css' />"));
} else if (window.oreintation == -90) {
$('link[title=android]')[0].disabled=true;
$("head").append($("<link title='android_90' rel='stylesheet' href='css/android_90.css' type='text/css' />"));
} else if (window.oreintation == 0){
$('link[title=android_90]')[0].disabled=true;
$("head").append($("<link title='android' rel='stylesheet' href='css/android.css' type='text/css' />"));
} else if (window.oreintation == 180){
$('link[title=android_90]')[0].disabled=true;
$("head").append($("<link title='android' rel='stylesheet' href='css/android.css' type='text/css' />"));
}
}, false);
//check on window.load
$(document).ready(function () {
if(window.orientation == 90) {
$('link[title=android]')[0].disabled=true;
$("head").append($("<link title='android_90' rel='stylesheet' href='css/android_90.css' type='text/css' />"));
} else if (window.oreintation == -90) {
$('link[title=android]')[0].disabled=true;
$("head").append($("<link title='android_90' rel='stylesheet' href='css/android_90.css' type='text/css' />"));
} else if (window.oreintation == 0){
$('link[title=android_90]')[0].disabled=true;
$("head").append($("<link title='android' rel='stylesheet' href='css/android.css' type='text/css' />"));
} else if (window.oreintation == 180){
$('link[title=android_90]')[0].disabled=true;
$("head").append($("<link title='android' rel='stylesheet' href='css/android.css' type='text/css' />"));
}
});发布于 2011-05-18 22:52:19
好的,
正如我在评论中所说,有一个条件问题:
if(window.orientation == 90)使用双精度=
不要对自己太苛刻,熟能生巧。
编辑:我不太确定:$('link[title=android]')[0]
将会改用$('link[title=android]').get(0)
https://stackoverflow.com/questions/6046330
复制相似问题