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)
1. es startup command: docker run -itd -e TAKE_FI...
Table of contents 1. What is SVN 2. Svn server an...
The function I want to achieve is to open a new w...
Sometimes we need to control whether HTML elements...
Here is how to install Tomcat-8.5.39 on centos7.6...
Introduction to sudo authority delegation su swit...
This article example shares the specific code of ...
1 Check the Linux distribution version [root@type...
Table of contents Preface Solution Tool Introduct...
GUN Screen: Official website: http://www.gnu.org/...
This article example shares the specific code of ...
Environment Introduction Operating system: centos...
Table of contents Preface Communication between t...
A distinct Meaning: distinct is used to query the...
Table of contents 1: Front-end handwritten paging...