JavaScript pop-up layer and background darkening code implementation

Source: Internet
Author: User

Do you know about the implementation methods of the JavaScript pop-up layer and background dimming? Here we will share with you the implementation code, hoping it will be helpful for your learning.

The JavaScript pop-up layer and background are dimmed.

In the JavaScript pop-up layer, the background is dimmed, and the code is not much. You can adjust it as needed. Here, the basic idea is implemented, and beautification is not very good.

The Code is as follows:

 
 
  1. <Title> JavaScript pop-up layer, dimmed background </title>
  2. <Script>
  3. VardocEle = function (){
  4. Returndocument. getElementById (arguments [0]) | false;
  5. }
  6. FunctionopenNewDiv (_ id ){
  7. Varm = "mask ";
  8. If (docEle (_ id) document. removeChild (docEle (_ id ));
  9. If (docEle (m) document. removeChild (docEle (m ));
  10. // Www.codefans.net new activation Layer
  11. VarnewDiv = document. createElement ("div ");
  12. NewDiv. id = _ id;
  13. NewDiv. style. position = "absolute ";
  14. NewDiv. style. zIndex = "9999 ";
  15. NewDiv. style. width = "200px ";
  16. NewDiv. style. height = "300px ";
  17. NewDiv. style. top = "100px ";
  18. NewDiv. style. left =
  19. (ParseInt (document. body. scrollWidth)-300)/2 + "px ";
  20. // Center the screen
  21. NewDiv. style. background = "EEEEEE ";
  22. NewDiv. style. border = "1 pxsolid # 0066cc ";
  23. NewDiv. style. padding = "5px ";
  24. NewDiv. innerHTML = "new activation layer content ";
  25. Document. body. appendChild (newDiv );
  26. // Mask Layer
  27. VarnewMask = document. createElement ("div ");
  28. NewMask. id = m;
  29. NewMask. style. position = "absolute ";
  30. NewMask. style. zIndex = "1 ";
  31. NewMask. style. width = document. body. scrollWidth + "px ";
  32. NewMask. style. height = document. body. scrollHeight + "px ";
  33. NewMask. style. top = "0px ";
  34. NewMask. style. left = "0px ";
  35. NewMask. style. background = "#000 ";
  36. NewMask. style. filter = "alpha (opacity = 40 )";
  37. NewMask. style. opacity = "0.40 ";
  38. Document. body. appendChild (newMask );
  39. // Docutmentwww.codefans.net
  40. // Close the mask and new layers.
  41. VarnewA = document. createElement ("");
  42. NewA. href = "#";
  43. NewA. innerHTML = "Disable the activation layer ";
  44. NewA. onclick = function (){
  45. Document. body. removeChild (docEle (_ id ));
  46. Document. body. removeChild (docEle (m ));
  47. Returnfalse;
  48. }
  49. NewDiv. appendChild (newA );
  50. }
  51. </Script>
  52. <Ahrefahref = "#" onclick = "openNewDiv (newDiv); returnfalse;">
  53. A new layer is displayed. </a>
  54.  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.