Apply HTML, CSS, JS to customize the popup effect

Source: Internet
Author: User

HTML section
First, there's a button to trigger the event.
Pop-up window background (usually full screen z-index and BackgroundColor)
Pop-up window container (header, body, footer)
It is worth mentioning that we generally give the element class name and ID
ID is used to get the element class used to set the style
CSS Section
Set the appropriate style first.
animation xx 2s with @keyframes to achieve animation effect
JavaScript section
Gets the popup element through the JS control css to make it hide or show
var modal = document.getElementById ("Simplemodal");

Get button Element
var modalbtn = document.getElementById ("modalbtn");

Get close Popup button element
var closebtn = document.getelementsbyclassname (' closebtn ') [0];

Listening to open pop-up events It's worth mentioning that the Listener command is similar to jquery's on.
Modalbtn.addeventlistener ("click", Openmodal);

Listen to close pop-up window events
Closebtn.addeventlistener ("click", Closemodal);

Monitor window close the pop-up window here in order to achieve the click of the window to achieve close
Window.addeventlistener ("click", Outsiteclick);


Pop-up window event
function Openmodal () {
Modal.style.display = "block";
}

Close the pop-up window
function Closemodal () {
Modal.style.display = "None";
}

Outsiteclick
function Outsiteclick (e) {
if (E.target = = modal) {
Modal.style.display = "None";
}
}

Apply HTML, CSS, JS to customize the popup effect

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.