[CSS] 客製作 Window Alert 樣式


HTML

  1. <!-- partial:index.partial.html -->
  2. <input type="button" value = "Test the alert" onclick="alert('Alert this pages');" />
  3. <!-- partial -->

CSS

  1. #modalContainer {
  2. background-color:rgba(0, 0, 0, 0.3);
  3. position:absolute;
  4. top:0;
  5. width:100%;
  6. height:100%;
  7. left:0px;
  8. z-index:10000;
  9. background-image:url(tp.png); /* required by MSIE to prevent actions on lower z-index elements */
  10. }
  11.  
  12. #alertBox {
  13. position:relative;
  14. width:33%;
  15. min-height:100px;
  16. max-height:400px;
  17. margin-top:50px;
  18. border:1px solid #fff;
  19. background-color:#fff;
  20. background-repeat:no-repeat;
  21. top:30%;
  22. }
  23.  
  24. #modalContainer > #alertBox {
  25. position:fixed;
  26. }
  27.  
  28. #alertBox h1 {
  29. margin:0;
  30. font:bold 1em Raleway,arial;
  31. background-color:#f97352;
  32. color:#FFF;
  33. border-bottom:1px solid #f97352;
  34. padding:10px 0 10px 5px;
  35. }
  36.  
  37. #alertBox p {
  38. height:50px;
  39. padding-left:5px;
  40. padding-top:30px;
  41. text-align:center;
  42. vertical-align:middle;
  43. }
  44.  
  45. #alertBox #closeBtn {
  46. display:block;
  47. position:relative;
  48. margin:10px auto 10px auto;
  49. padding:7px;
  50. border:0 none;
  51. width:70px;
  52. text-transform:uppercase;
  53. text-align:center;
  54. color:#FFF;
  55. background-color:#f97352;
  56. border-radius: 0px;
  57. text-decoration:none;
  58. outline:0!important;
  59. }
  60.  
  61. @media (max-width: 600px)
  62. {
  63. #alertBox {
  64. position:relative;
  65. width:90%;
  66. top:30%;
  67. }

JS

  1. var ALERT_TITLE = "Oops!";
  2. var ALERT_BUTTON_TEXT = "Ok";
  3.  
  4. if(document.getElementById) {
  5. window.alert = function(txt) {
  6. createCustomAlert(txt);
  7. }
  8. }
  9.  
  10. function createCustomAlert(txt) {
  11. d = document;
  12.  
  13. if(d.getElementById("modalContainer")) return;
  14.  
  15. mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
  16. mObj.id = "modalContainer";
  17. mObj.style.height = d.documentElement.scrollHeight + "px";
  18. alertObj = mObj.appendChild(d.createElement("div"));
  19. alertObj.id = "alertBox";
  20. if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
  21. alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
  22. alertObj.style.visiblity="visible";
  23.  
  24. h1 = alertObj.appendChild(d.createElement("h1"));
  25. h1.appendChild(d.createTextNode(ALERT_TITLE));
  26.  
  27. msg = alertObj.appendChild(d.createElement("p"));
  28. //msg.appendChild(d.createTextNode(txt));
  29. msg.innerHTML = txt;
  30.  
  31. btn = alertObj.appendChild(d.createElement("a"));
  32. btn.id = "closeBtn";
  33. btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
  34. btn.href = "#";
  35. btn.focus();
  36. btn.onclick = function() { removeCustomAlert();return false; }
  37.  
  38. alertObj.style.display = "block";
  39. }
  40.  
  41. function removeCustomAlert() {
  42. document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
  43. }
  44. function ful(){
  45. alert('Alert this pages');
  46. }
Demo

沒有留言:

技術提供:Blogger.