歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> js讓網頁適應屏幕大小

js讓網頁適應屏幕大小

日期:2017/3/1 10:13:08   编辑:Linux編程

如果你的網頁不經常更新,而且對頁面效果極其在意,那好,你就設計兩個頁面,分別對應800×600和1024×768兩種分辨率。把這兩個首頁文件分別命名為index800.htm和index1024.htm 。然後在空白的索引頁index.htm中加入以下代碼到前面:

  1. <Script language=”javascript”>
  2. if (window.screen){
  3. var w=screen.width;
  4. url_800=”index800.htm”;
  5. url_1024=”index1024.htm”
  6. //請根據你的文件命名修改
  7. if (w<835){
  8. self.location.replace(url_800);
  9. }//加入判斷條件,還可以用“&”加入多個判斷條件
  10. if (w>=835){
  11. self.location.replace(url_1024);
  12. }
  13. }
  14. </Script>
Copyright © Linux教程網 All Rights Reserved