大家好,又见面了,我是你们的朋友全栈君。
页面加载完成页面右下角出现小窗口,倒计时5秒关闭,也可自行手动关闭
代码如下:
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Document</title>
<style>
.banner {
width: 260px;
height: 200px;
background-color: #999;
position: fixed;
right: 0;
bottom: 0;
}
em {
margin-right: 195px;
}
</style>
</head>
<body>
<div class=”banner”>
<em>5s</em>
<input type=”button” value=”关闭” id=”stop”>
</div>
<script>
let banner = document.querySelector(“.banner”);
let em = document.querySelector(“em”);
let stop0 = document.querySelector(“#stop”);
let y = -200;
let timer = setInterval(function () {
y ;
banner.style.cssText = `bottom: ${y}px;`;
if (y >= 0) {
time();
clearInterval(timer);
}
}, 5);
// 按钮关闭
stop0.onclick = function () {
Object.assign(banner.style, {
display: “none”
})
};
// 5秒倒计时关闭
function time() {
let second = 5;
let timer = setInterval(function () {
second–
em.innerHTML = `${second}s`;
if (second == 0) {
clearInterval(timer);
Object.assign(banner.style, {
display: “none”
})
}
}, 1000);
}
</script>
</body>
</html>
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155329.html原文链接:https://javaforall.cn