日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

移动端Web开发如何处理横竖屏

發(fā)布時間:2023/12/18 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 移动端Web开发如何处理横竖屏 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<!Doctype html> <html> <head> <meta charset="utf-8"> <meta id="viewport" name="viewport" content="width=device-width,initial-scale=1.0;"> <title>橫豎屏切換檢測</title> <style type="text/css"> .landscape body { background-color: #ff0000; }.portrait body { background-color: #00ffff; } </style> <script type="text/javascript"> // window.orientation :這個屬性給出了當前設備的屏幕方向,0表示豎屏,正負90表示橫屏(向左與向右)模式 // onorientationchange : 在每次屏幕方向在橫豎屏間切換后,就會觸發(fā)這個window事件,用法與傳統(tǒng)的事件類似 (function(){ var supportOrientation=(typeof window.orientation == "number" && typeof window.onorientationchange == "object"); //判斷瀏覽器是否支持orientationvar updateOrientation=function(){ if(supportOrientation){ updateOrientation=function(){ var orientation=window.orientation; switch(orientation){ case 90: case -90: orientation="landscape"; //橫屏 break; default: orientation="portrait"; //豎屏 } document.body.parentNode.setAttribute("class",orientation); }; }else{ updateOrientation=function(){ //如果當前瀏覽器不支持orientation,則使用最簡單的方法(判斷窗口的高寬) var orientation=(window.innerWidth > window.innerHeight)? "landscape":"portrait"; document.body.parentNode.setAttribute("class",orientation); }; } updateOrientation(); };var init=function(){ updateOrientation(); if(supportOrientation){ window.addEventListener("orientationchange",updateOrientation,false); }else{ window.setInterval(updateOrientation,5000); } }; window.addEventListener("DOMContentLoaded",init,false); })(); </script> </head> <body> <div> 移動端Web開發(fā)如何處理橫豎屏 </div> </body> </html>

  

轉載于:https://www.cnblogs.com/kt520/p/5681563.html

總結

以上是生活随笔為你收集整理的移动端Web开发如何处理横竖屏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。