Jquery使容器自適應瀏覽器視窗

來源:互聯網
上載者:User

標籤:適應   http   大小   pre   容器   win   span   str   size   

一、幾個關鍵點

      1:當文檔大小改變時可以通過哪個事件來觸發?

           resize([Data], fn) 可傳入data供函數fn處理。

          樣本:       

$(window).resize(function(){      alert("Stop it!");  });  

     2:怎樣獲得瀏覽器視窗的寬度高度?    

           擷取當前瀏覽器視窗的寬度

$(window).width(); 

    擷取第一段的寬

$("p").width()

       擷取當前HTML文檔寬度

$(document).width();

       3:怎樣賦值?

           方法很多,可以通過css(...)、width(...)等

二、舉個例子

 

<html>  <head>  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  <title>jquery自適應demo</title>  </head>  <script type="text/javascript" src="jquery-1.7.1.min.js"></script>  <script>  $(document).ready(function(){      //初始化寬度、高度      $("#div1").width($(window).width());      $("#div1").height($(window).height());      //當文件視窗發生改變時 觸發      $(window).resize(function(){          $("#div1").width($(window).width());          $("#div1").height($(window).height());      })      })  </script>  <body style="margin:0;">      <div id="div1" style="background:#09F">          這是一個可以自適應視窗的DIV      </div>  </body>  </html>  

 

Jquery使容器自適應瀏覽器視窗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.