javascript countdown prompt box

javascript countdown prompt box

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:
  • JavaScript countdown and pop-up window prompt special effects
  • JS countdown implementation code (hours, minutes, seconds)
  • JS countdown (days, hours, minutes, seconds)
  • Simple and easy to use countdown js code
  • js code to realize the 60-second countdown when clicking the button
  • 2 simple js countdown methods
  • Example of implementing a simple countdown function using native JS
  • js countdown jump example after a few seconds
  • A good js html page countdown can be accurate to seconds
  • js realizes the countdown effect of clicking to get the verification code

<<:  Detailed tutorial on installing JDK1.8 on Linux

>>:  MySQL InnoDB monitoring (system layer, database layer)

Recommend

Detailed explanation of docker version es, milvus, minio startup commands

1. es startup command: docker run -itd -e TAKE_FI...

SVN installation and basic operation (graphic tutorial)

Table of contents 1. What is SVN 2. Svn server an...

Vue opens a new window and implements a graphic example of parameter transfer

The function I want to achieve is to open a new w...

Hide HTML elements through display or visibility

Sometimes we need to control whether HTML elements...

How to install Tomcat-8.5.39 on centos7.6

Here is how to install Tomcat-8.5.39 on centos7.6...

Delegating Privileges in Linux Using Sudo

Introduction to sudo authority delegation su swit...

Vue+element ui realizes anchor positioning

This article example shares the specific code of ...

Detailed tutorial for installing mysql5.7.18 on centos7.3

1 Check the Linux distribution version [root@type...

How to solve the synchronization delay caused by MySQL DDL

Table of contents Preface Solution Tool Introduct...

Detailed explanation of screen command usage in Linux

GUN Screen: Official website: http://www.gnu.org/...

jQuery implements employee management registration page

This article example shares the specific code of ...

Detailed process of zabbix monitoring process and port through agent

Environment Introduction Operating system: centos...

Detailed explanation of how two Node.js processes communicate

Table of contents Preface Communication between t...

Detailed example of using the distinct method in MySQL

A distinct Meaning: distinct is used to query the...

An article tells you how to implement Vue front-end paging and back-end paging

Table of contents 1: Front-end handwritten paging...