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

Analyzing Linux high-performance network IO and Reactor model

Table of contents 1. Introduction to basic concep...

Detailed explanation of SSH password-free login configuration under Linux

Assume there are two Linux servers A and B, and w...

Detailed explanation of MySql 5.7.17 free installation configuration tutorial

1. Download the mysql-5.7.17-winx64.zip installat...

Linux parted disk partition implementation steps analysis

Compared with fdisk, parted is less used and is m...

About using Alibaba's iconfont vector icon in Vue

There are many import methods on the Internet, an...

Docker installation and deployment example on Linux

After reading the following article, you can depl...

Detailed explanation of Linux one-line command to process batch files

Preface The best method may not be the one you ca...

MySQL sorting Chinese details and examples

Detailed explanation of MySQL sorting Chinese cha...

Pure CSS to adjust Div height according to adaptive width (percentage)

Under the requirements of today's responsive ...

Docker installation and configuration steps for RabbitMQ

Table of contents Single-machine deployment Onlin...

Detailed explanation of the function and usage of DOCTYPE declaration

1. Browser rendering mode and doctype Some web pa...

Introduction to the process of building your own FTP and SFTP servers

FTP and SFTP are widely used as file transfer pro...

How to use flat style to design websites

The essence of a flat website structure is simpli...

Vue implements online preview of PDF files (using pdf.js/iframe/embed)

Preface I am currently working on a high-quality ...

Detailed explanation of this pointing problem in JavaScript function

this keyword Which object calls the function, and...