1、需要注意雪花元素定位一定要是fixed定位,否则雪花落到哪里body的高度就会增加到哪里,就不会掉到画外了 。
2、应该能封装起来引用,后续有空在研究一下。
这里是html内容。
<!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>aaaaa</title>
<!-- 圣诞主题 -->
<link rel="stylesheet" href="/ChristmasIndex.css">
</head>
<body>
<div id="app" style="width:100%;height:100%;background-color:red">
<!--这些都是雪花图片-->
<div class="Xmas-flower1 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54e1.png" alt="">
</div>
<div class="Xmas-flower11 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54e1.png" alt="">
</div>
<div class="Xmas-flower12 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54e1.png" alt="">
</div>
<div class="Xmas-flower13 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54e1.png" alt="">
</div>
<div class="Xmas-flower2 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54f1.png" alt="">
</div>
<div class="Xmas-flower21 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54f1.png" alt="">
</div>
<div class="Xmas-flower22 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54f1.png" alt="">
</div>
<div class="Xmas-flower23 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da54f1.png" alt="">
</div>
<div class="Xmas-flower3 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower31 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower32 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower33 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower34 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower35 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower36 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower37 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da612c.png" alt="">
</div>
<div class="Xmas-flower4 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da59c2.png" alt="">
</div>
<div class="Xmas-flower41 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da59c2.png" alt="">
</div>
<div class="Xmas-flower42 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da59c2.png" alt="">
</div>
<div class="Xmas-flower43 flower">
<img src="https://i.loli.net/2018/12/17/5c177f8da59c2.png" alt="">
</div>
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data() {
},
mounted: function () {},
methods: {
}
})
</script>
</body>
</html>
下面是CSS
body {
color: #fff;
background-color: #BB2635;
overflow: hidden;
/* position: relative; */
height: 100%;
width: 100%;
}
.flower img{
width: 100%;
height: 100%;
}
/*
**这里@keyframes注册动画,snowing1为动画名称,后面需要引用
*/
@keyframes snowing1 {
/* 从顶上画外下落到1000像素的地方,手机端自然就是已经在画外了。 */
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower1 {
/* 这里设定雪花元素的大小 */
width: 50px;
height: 50px;
/* 这里需要注意定位一定要是fixed定位,否则雪花落到哪里body的高度就会增加到哪里,就不会掉到画外了 ,这里点搞了好久才知道的,教训*/
position: fixed;
top:-100px;
/* 击穿,雪花元素不会阻挡到其他的点击事件 */
pointer-events:none;
left:3%;
/* 下面这些就是css里能看到的了 */
animation-name: snowing1;
animation-duration: 10s;
animation-timing-function: linear;
/* animation-delay: 2s; */
animation-iteration-count: infinite;
}
.Xmas-flower11 {
width: 35px;
height: 35px;
position: fixed;
top:-100px;
pointer-events:none;
left:3%;
animation-name: snowing1;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 5s;
animation-iteration-count: infinite;
}
@keyframes snowing12 {
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower12 {
width: 50px;
height: 50px;
position: fixed;
top:-100px;
pointer-events:none;
left:60%;
animation-name: snowing12;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
}
.Xmas-flower13 {
width: 50px;
height: 50px;
position: fixed;
top:-100px;
pointer-events:none;
left:60%;
animation-name: snowing12;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 7s;
animation-iteration-count: infinite;
}
@keyframes snowing2 {
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower2 {
width: 40px;
height: 40px;
position: fixed;
top:-100px;
pointer-events:none;
left:25%;
animation-name: snowing2;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 3s;
animation-iteration-count: infinite;
}
.Xmas-flower21 {
width: 45px;
height: 45px;
position: fixed;
top:-100px;
pointer-events:none;
left:25%;
animation-name: snowing2;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay:8s;
animation-iteration-count: infinite;
}
@keyframes snowing22 {
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower22 {
width: 45px;
height: 45px;
position: fixed;
top:-100px;
pointer-events:none;
left:90%;
animation-name: snowing22;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 4s;
animation-iteration-count: infinite;
}
.Xmas-flower23 {
width: 40px;
height: 40px;
position: fixed;
top:-100px;
pointer-events:none;
left:90%;
animation-name: snowing22;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 9s;
animation-iteration-count: infinite;
}
@keyframes snowing3 {
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower3 {
width: 60px;
height: 60px;
position: fixed;
top:-100px;
pointer-events:none;
left:45%;
animation-name: snowing3;
animation-duration: 10s;
animation-timing-function: linear;
/* animation-delay: 2s; */
animation-iteration-count: infinite;
}
.Xmas-flower31 {
width: 60px;
height: 60px;
position: fixed;
top:-100px;
pointer-events:none;
left:45%;
animation-name: snowing3;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 5s;
animation-iteration-count: infinite;
}
.Xmas-flower34 {
width: 30px;
height: 30px;
position: fixed;
top:-100px;
pointer-events:none;
left:10%;
animation-name: snowing3;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 7s;
animation-iteration-count: infinite;
}
.Xmas-flower35 {
width: 40px;
height: 40px;
position: fixed;
top:-100px;
pointer-events:none;
left:27%;
animation-name: snowing3;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 1s;
animation-iteration-count: infinite;
}
.Xmas-flower36 {
width: 20px;
height: 20px;
position: fixed;
top:-100px;
pointer-events:none;
left:38%;
animation-name: snowing3;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 7s;
animation-iteration-count: infinite;
}
.Xmas-flower37 {
width: 50px;
height: 50px;
position: fixed;
top:-100px;
pointer-events:none;
left:77%;
animation-name: snowing3;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 8s;
animation-iteration-count: infinite;
}
@keyframes snowing32 {
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower32 {
width: 60px;
height: 60px;
position: fixed;
top:-100px;
pointer-events:none;
left:6%;
animation-name: snowing32;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
}
.Xmas-flower33 {
width: 35px;
height: 35px;
position: fixed;
top:-100px;
pointer-events:none;
left:45%;
animation-name: snowing32;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 6s;
animation-iteration-count: infinite;
}
@keyframes snowing4 {
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower4 {
width: 10px;
height: 10px;
position: fixed;
top:-100px;
pointer-events:none;
left:75%;
animation-name: snowing4;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 3s;
animation-iteration-count: infinite;
}
.Xmas-flower41 {
width: 15px;
height: 15px;
position: fixed;
top:-100px;
pointer-events:none;
left:75%;
animation-name: snowing4;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 9s;
animation-iteration-count: infinite;
}
@keyframes snowing42 {
0% {top: -60px;}
100% {top: 1000px;}
}
.Xmas-flower42 {
width: 15px;
height: 15px;
position: fixed;
top:-100px;
pointer-events:none;
left:15%;
animation-name: snowing42;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 4s;
animation-iteration-count: infinite;
}
.Xmas-flower43 {
width: 10px;
height: 10px;
position: fixed;
top:-100px;
pointer-events:none;
left:15%;
animation-name: snowing42;
animation-duration: 10s;
animation-timing-function: linear;
animation-delay: 9s;
animation-iteration-count: infinite;
}