Files
ClassContent/历届学生/front-end-team/项目练习/学生项目/陆旗/js练习/i.html
2024-09-27 02:06:13 +08:00

146 lines
2.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>红包雨</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
body {
height: 100%;
height: 100%;
position: relative;
height: 100vh;
overflow: hidden;
}
img {
width: 80px;
position: absolute;
}
.alert {
position: fixed;
width: 100%;
height: 100%;
background: #0000008f;
display: flex;
align-items: center;
justify-content: center;
z-index: 8;
}
.alert .alert_warp {
width: 32%;
background: #fff;
height: 300px;
padding: 15px;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
.alert_warp .alert_title {
display: flex;
justify-content: space-between;
height: 45px;
align-items: center;
border-bottom: 1px solid #e6e6e6;
}
.alert_title span {}
.alert_body {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
.hidden {
display: none;
}
</style>
<body>
<div class="alert hidden">
<div class="alert_warp">
<div class="alert_title">
<span>恭喜中奖</span>
<span class="close">x</span>
</div>
<div class="alert_body">
恭喜抽中9折优惠券
</div>
</div>
</div>
</body>
<script>
var clientHeight = $('body').clientHeigh,
clientWidth = $('body').clientWidth,
body = $('body');
img.onclick = function(){
}
function createdHb() {
var x = parseInt(Math.random() * clientHeight - 80);
var img = document.createElement('img');
img.src = './hb.png'
img.style = `
left:${x}px;
top:-100px
`
body.appendChild(img)
motion(img)
console.log(img);
}
function motion(el) {
setInterval(function () {
el.style.top = `${parseInt(el.style.top) + 1}px`
}, 6)
}
// setInterval(function () {
// createdHb()
//}, 1000)
createdHb()
function $(className) {
return document.querySelector(className) //封装统一类名
}
</script>
</html>