This article example shares the specific code of javascript to implement the countdown prompt box for your reference. The specific content is as follows Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Full screen prompt box</title> <style> #button{ width: 150px; height: 50px; background-color: greenyellow; } .fullScreenDiv{/* full screen div */ display: none; position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.4); } .promptDiv{/* prompt box div */ display: none; position: absolute; left: 50%; top: 50%; transform: translateX(-50%) translateY(-50%); width: 30%; height: 30%; border-radius: 20px; background-color:white; text-align: center; } .close{ height: 34px; line-height: 34px; margin: 0px; text-align: right; border-top-left-radius: 20px; border-top-right-radius: 20px; background-color: cornflowerblue } .X{ padding: 2px 6px; margin-right: 8px; color: white; cursor: pointer; } .countDown{/*Countdown to close the prompt box*/ color: red; font-size: 28px; } </style> <script> window.onload = function(){ document.getElementById("button").addEventListener("click",function(){ document.getElementsByClassName("fullScreenDiv")[0].style.display="block"; document.getElementsByClassName("promptDiv")[0].style.display="block"; for(var i=5;i>=0;i--){ (function(i){ setTimeout(function(){ var j=Math.abs(i-5); //If i is 0, then the timer is 0s, and the output is abs(0-5)=5. If i is 5, then the timer is 5s, and the output is abs(i-5)=0. if(j==0){ document.getElementsByClassName("fullScreenDiv")[0].style.display="none"; document.getElementsByClassName("promptDiv")[0].style.display="none"; }else{ document.getElementsByClassName("countDown")[0].innerHTML=j; } },i*1000);//Each interval is 1s })(i); } }); document.getElementsByClassName("X")[0].addEventListener("click",function(){ document.getElementsByClassName("fullScreenDiv")[0].style.display="none"; document.getElementsByClassName("promptDiv")[0].style.display="none"; }); } </script> </head> <body> <div> <button id="button">Open full screen prompt box</button> </div> <div class="fullScreenDiv"> <div class="promptDiv"> <h4 class="close"><span class="X">X</span></h4> <p>I am a full screen prompt box. I am a full screen prompt box. I am a full screen prompt box.</p> <p>Countdown Close</p> <span class="countDown">5</span> </div> </div> </body> </html> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed tutorial on installing JDK1.8 on Linux
>>: MySQL InnoDB monitoring (system layer, database layer)
Table of contents 1. Introduction to basic concep...
Assume there are two Linux servers A and B, and w...
1. Download the mysql-5.7.17-winx64.zip installat...
Compared with fdisk, parted is less used and is m...
There are many import methods on the Internet, an...
After reading the following article, you can depl...
Preface The best method may not be the one you ca...
Detailed explanation of MySQL sorting Chinese cha...
Under the requirements of today's responsive ...
Table of contents Single-machine deployment Onlin...
1. Browser rendering mode and doctype Some web pa...
FTP and SFTP are widely used as file transfer pro...
The essence of a flat website structure is simpli...
Preface I am currently working on a high-quality ...
this keyword Which object calls the function, and...