標籤:頁面配置 登入 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學習進階-頁面覆蓋