美文网首页
简陋的实现圣诞落雪动画

简陋的实现圣诞落雪动画

作者: Kawing_Zhang | 来源:发表于2018-12-21 23:56 被阅读0次

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;
}


相关文章

  • 简陋的实现圣诞落雪动画

    1、需要注意雪花元素定位一定要是fixed定位,否则雪花落到哪里body的高度就会增加到哪里,就不会掉到画外了 。...

  • 梦想的本质

    圣诞节刚过第一天,下雪了。晚上落雪和白天落雪不一样,夜间落雪,道路结冰的几率就会大大增加,第二天乘车就会不方便。而...

  • 雪落,雪落

    夜里风急,呼啸着刮过来刮过去,像搜刮民脂民膏的军阀,被风吹光叶子的树,光秃秃的站在黑夜里,没有御寒的衣服,也没有一...

  • 雪落,雪落

    天气预报很准。 刚刚拿起手机,朋友圈里各种雪落的视频。 我在猜想,明日清晨的雪会有多厚? 上班的交通问题反倒成了困...

  • 翻页动画

    #pragmaCATransition动画实现/** * 动画效果实现 * @param type 动画的类型 ...

  • 自己实现的简陋的promise

    没有状态

  • 当时明月在—圣诞

    再见思慕 圣诞节会下雪吗? 冰格一遍又一遍问自己,不知道从何时开始,特别期待圣诞节的雪落。两个人的圣诞太过冷清,安...

  • 圣诞落初雪

    今天下雪了,初雪落疮地,绿草披白铠。 圣诞降雪,是不是晚上圣诞老人给我送礼物? 因为雪喜,喜欢她的洁,喜欢她的净,...

  • 绿毛怪格林奇

    今天陪小朋友一起去看了动画片,临近圣诞节,这部带着圣诞气味的动画片格外受欢迎。 绿色的圣诞怪杰处处搞怪,在人类社会...

  • 简陋的Vue-Router实现

    前言 源码地址 好奇 Vue 与 Vue-Router 是怎么形成关联,怎么去渲染的,就出现了这篇总结的文章。在使...

网友评论

      本文标题:简陋的实现圣诞落雪动画

      本文链接:https://www.haomeiwen.com/subject/pqybkqtx.html