javascript实现倒计时提示框
作者:友人CWH 发布时间:2024-04-22 22:30:35
标签:js,倒计时,提示框
本文实例为大家分享了javascript实现倒计时提示框的具体代码,供大家参考,具体内容如下
代码:
<!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>全屏提示框</title>
<style>
#button{
width: 150px;
height: 50px;
background-color: greenyellow;
}
.fullScreenDiv{/* 全屏div */
display: none;
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.4);
}
.promptDiv{/* 提示框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{/*倒计时关闭提示框*/
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);//如果i为0,那么被定时0s,则要输出abs(0-5)=5 ,如果i为5,那么被定时5s,则要输出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);//每次间隔时间为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">打开全屏提示框</button>
</div>
<div class="fullScreenDiv">
<div class="promptDiv">
<h4 class="close"><span class="X">X</span></h4>
<p>我是全屏提示框我是全屏提示框我是全屏提示框</p>
<p>倒计时关闭</p>
<span class="countDown">5</span>
</div>
</div>
</body>
</html>
来源:https://blog.csdn.net/CWH0908/article/details/89736836
0
投稿
猜你喜欢
- 查询操作和性能优化1.基本操作增models.Tb1.objects.create(c1='xx', c2='oo&
- 问题初始化数据库时mysqld --initialize --user mysql报错:mysqld: error while loadin
- JS在firefox中的兼容性问题,自己也经常遇到.此文是网上资料,不过时间较久不记得原址了...1. document.form.item
- HTTPX是Python3的功能齐全的HTTP客户端,它提供同步和异步API,并支持HTTP/1.1和HTTP/2安装pip install
- 当然这应该属于正常过滤手法,而还有一种过滤HTML标签的最终极手法,则是将一对尖括号及尖括号中的所有字符均替换不显示,该方法对于内容中必须描
- 摘要:近几天在做一个东西,其中需要对图像中的文字进行识别,看了前辈们的文章,找到两个较简单的方法:使用python的pytesseract库
- 开始码代码之前,我们先来了解一下三种邮件服务协议:1、SMTP协议SMTP(Simple Mail Transfer Protocol),即
- 有一个表user,字段分别有id、nick_name、password、email、phone。一、单字段(nick_name)查出所有有重
- 代码如下,保存到HTML文件也可以查看效果:<html><head><meta charset="u
- 个人认为rollup在打包组件的实现方式比用webpack方便,webpack应该是比较适合打包大型的工程项目,而rollup适合打包一些平
- Python中为了方便程序直接生成exe文件,它存在一个pyinstaller库,使用这个库可以直接将.py程序生成exe文件。这个命令不是
- 接触了Vue模块化开发才发现JavaScript组件化开发的演变一直在继续,以前也没有特别在意这一块内容,写着代码能调试运行不报错就可以了,
- 简介几年前,我用C#写了一个RSS阅读器,但是我想如果把它做成一个SPA(单页应用)效果会更好。 Angular使一些事情变得简单,RSS阅
- 一、常量常量是一个简单值的标识符(名字)。如同其名称所暗示的,在脚本执行期间该值不能改变(除了所谓的魔术常量,它们其实不是常量)。常量默认为
- 版本:平台:ubuntu 14 / I5 / 4G内存python版本:python2.7opencv版本:2.13.4依赖:如果系统没有p
- 如下所示:fig.tight_layout()#调整整体空白 plt.subplots_adjust(wspace =0, hspace =
- 本文实例讲述了javascript获取select值的方法。分享给大家供大家参考。具体分析如下:1. 获取显示的汉字document.get
- 【OpenCV】⚠️高手勿入! 半小时学会基本操作 ⚠️ 圆圈检测概述OpenCV 是一个跨平台的计算机视觉库, 支持多语言, 功能强大.
- 1、字符串的每行末尾使用 \ 续行以多行的形式书写字符串,每行的末尾使用 \ 续行。需要注意输出内容为一行。>>> str
- 本文实例讲述了Python2.7中SQLite3基本操作方法。分享给大家供大家参考,具体如下:1、基本操作# -*- coding: utf