In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to click on the background of the mask layer and close the effect of the mask layer in Html5. The article is very detailed and has a certain reference value. Interested friends must finish reading it!
Html Code:
There is only one button displayed on the page, a div with an ID of bg as a gray background mask layer, a div with an ID of popup as a pop-up window for red packets, and a div with an ID of close as a close button.
Show X
CSS code
There are no technical difficulties in the css code, the only thing to pay attention to is to absolutely locate the mask layer of the gray background. It would be fine if both top and lefe are 0.
Body {position: relative;} .btn {width: 100px; height: 40px; line-height: 40px; text-align: center; margin:20px auto 0; border: 1px solid # 333; border-radius: 10px;} .bg {width: 100%; height: 100%; position: fixed; top: 0 Left: 0; background-color: rgba (0,0,0, .6); display: none;} .popup {width: 260px; height: 320px; background: red; position: absolute; top: 50%; left: 50%; transform: translate (- 50%,-50%); border-radius: 15px } .popup .close {width: 30px; height: 30px; line-height: 30px; text-align: center; position: absolute; top:-40px; right: 0px; border: 1px solid # 999; border-radius: 50%; color: # 999;}
JS Code:
Var btn = document.getElementById ('btn'); var bg = document.getElementById (' bg'); var popup = document.getElementById ('popup'); var closeBtn = document.getElementById (' close'); / / Click the display button to display the pop-up window btn.addEventListener ('click', () = > {bg.style.display =' block';}) / / Click the shadow mask layer to close the pop-up window bg.addEventListener ('click', (e) = > {bg.style.display =' none'}); / / prevent the bubbling event, and clicking the pop-up window will not execute the click event popup.addEventListener of the parent element ('click', (e) = > {e.stopPropagation ();}) / / Click the closing symbol to close the pop-up window closeBtn.addEventListener ('click', (e) = > {e.stopPropagation (); bg.style.display =' none'}). The above is all the contents of the article "how to click on the background of the mask layer and close the effect of the mask layer in Html5". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.