js學習進階-頁面覆蓋

來源:互聯網
上載者:User

標籤:頁面配置   登入   nod   空間   code   res   attribute   document   content   

頁面覆蓋以顯示一條資訊,照片或者常見的登入,廣告,

執行個體:

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width">  <title>JS Bin</title>  <style>    .overlay{      background-color:#000;      opacity:.5;      filter:alpha(opacity=50);      position:fixed;      top:0;left:0;      width:100%;height:100%;      z-index:10;    }    .overlaymsg{      position:absolute;      background-color:yellow;      padding:10px;      width:200px;      height:200px;      font-size:2em;      z-index:11;      top:50%;      left:50%;      margin-left:-100px;      margin-top:-100px;    }  </style>  <script>     function displayPopup(){              var overlay = document.createElement("div");       overlay.setAttribute("id","overlay");       overlay.setAttribute("class","overlay");       document.body.appendChild(overlay);              var msg = document.createElement("div");       var txt = document.createTextNode("please join our mailing list!(click to close)");       msg.appendChild(txt);       msg.setAttribute("id","msg");       msg.setAttribute("class","overlaymsg");              msg.onclick = restore;       document.body.appendChild(msg);     }        function restore(){      document.body.removeChild(document.getElementById("overlay"));      document.body.removeChild(document.getElementById("msg"));          }        window.onload = function(){      displayPopup();    }  </script></head><body><p>Existing material.</p></body></html>

特點:覆蓋整個web頁面,設定遮布(樣式overlay)的寬高為100%,要能看見底部的資訊,設定透明度:opacity:.5;filter:alpha(opacity=50);

    訊息顯示(樣式overlaymsg)設定要在遮布之上,設定z-index 的值遠大於遮布,置中顯示,設定左邊距和上邊距50%。

    最後一個要確保上下滾動滑鼠時,樣式一致,設定遮布定位方式為:fixed;

顯示隱藏頁面:

*.style.hidden = "visible";

*.style.hidden = "hidden";

特點:任然佔用了物理空間,影響其他的元素,

*.style.display = "block";

*.style.display = "none";

特點:完全從頁面配置中刪除了該元素,

display其他的屬性值:inline-block  內容像一個區塊層級元素格式化,然後像內嵌元素排練

    inherit   預設顯示,繼承該元素的父節點

補充:

塊元素:div  , p  , form,   ul,  li ,  ol, dl,   address,  fieldset,  hr, menu,  table

行內元素:span,   strong,   em, img ,  input,  select,  textarea, 

js學習進階-頁面覆蓋

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.