本文實例講述了javascript實現根據iphone屏幕方向調用不同樣式表的方法。分享給大家供大家參考。具體如下:
當iphone屏幕旋轉式,這段JS代碼可以動態調用不同的樣式來適應屏幕變換
<script type="text/javascript">
function orient()
{
switch(window.orientation){
case 0: document.getElementById("orient_css").href = "css/iphone_portrait.css";
break;
case -90: document.getElementById("orient_css").href = "css/iphone_landscape.css";
break;
case 90: document.getElementById("orient_css").href = "css/iphone_landscape.css";
break;
}
window.onload = orient();
</script>
希望本文所述對大家的javascript程序設計有所幫助。