简陋的实现圣诞落雪动画

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


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,607评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,047评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,496评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,405评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,400评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,479评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,883评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,535评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,743评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,544评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,612评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,309评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,881评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,891评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,136评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,783评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,316评论 2 342