首页 前端知识 【中秋征文】手把手教你海面月亮升起中秋节特效制作

【中秋征文】手把手教你海面月亮升起中秋节特效制作

2024-05-20 14:05:17 前端知识 前端哥 600 84 我要收藏

今年的中秋又要到啦,不管你身在何处,与何人共度,中秋的团圆之情、欢聚之乐是一直不变的。

独在异乡为异客,每逢佳节倍思亲。

  • 一,前言
    • 赏析
  • 二,效果
    • 1, 静态效果
    • 2,视频效果
  • 三,思路
  • 四,代码
    • 1,目录结构
    • 2,index.html代码
    • 3,style.css样式代码
    • 4,素材图
    • 5,js脚本
  • 五,结语

一,前言

又是一年中秋节,明月千里寄相思 秋风起,日渐凉,时光似水般轻轻从指尖划过,转眼又是一年 一度的中秋节。这篇文章将以程序员的方式呈现中秋佳节,希望大家喜欢,祝你们中秋快乐!

《望月怀远》是唐代诗人张九龄的作品。此诗是望月怀思的名篇。

在这里插入图片描述

赏析

《望月怀远》是一首月夜怀念远人的诗,是作者在离乡时,望月而思念远方亲人而写的。起句“海上生明月,天涯共此时”,茫茫的海上升起一轮明月,此时你我都在天涯共相望。有情之人都怨恨月夜漫长,整夜里不眠而把亲人怀想。熄灭蜡烛怜爱这满屋月光,我披衣徘徊深感夜露寒凉。不能把美好的月色捧给你,只望能够与你相见在梦乡。

二,效果

1, 静态效果

在这里插入图片描述

2,视频效果

Video_2022-08-29_170802

三,思路

  1. 首先,我们要创建一个定时器,使得月亮 div id=“moon” 不断上升!
  2. 当月亮上升到距离顶部,同时显示starUnder130像素时,清除定时器,月亮上升停止!
  3. 当月亮停止之后,让里面的诗句逐字(定时器实现)显示,通过设置的动画让嫦娥图片显示!
  4. class="stars"是创建夜空中的星星,并加上css动画让其动起来!
  5. div id=“water” 是底部倒影

四,代码

1,目录结构

在这里插入图片描述

2,index.html代码

<!DOCTYPE html>
<html > 
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>海面月亮升起中秋节特效</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery.min.js"></script>
  </head>
<body> 
  <div id="bg">
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div class="stars"></div>
    <div id="water">
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    <div class="starUnder"></div>
    </div>
    <div id="moon">
    </div>
    </div>

    <script>
    $(document).ready(function(){
      var poem1=["海","上","升","明","月"];
      var poem2=["天","涯","共","此","时"];
      var arrWid=[0,80,320];
      var arrHgt=[0,10,200];
      var posTop=[0,2,13,46];
      var spdWid=16;
      var spdHgt=10;
      var moon=document.getElementById("moon");
      var water=document.getElementById("water"); 
      var Ocean=document.getElementsByClassName("Ocean");
      moon.style.top=670 + "px";
      var timer=setInterval(function(){
        moon.style.top=moon.offsetTop - 10 + "px";
        if(moon.offsetTop>=660){
         bg(arrWid[0],arrHgt[0],0);
        }else if(moon.offsetTop>=440){
          if(arrWid[1]>=200||arrHgt[1]>=110){
            spdHgt=7.5;
            spdWid=8;
          }
          arrWid[1]+=spdWid;
          arrHgt[1]+=spdHgt;
          
          bg(arrWid[1],arrHgt[1],0);
        }else if(moon.offsetTop>=430){
          bg(arrWid[2],arrHgt[2],0);
        }else if(moon.offsetTop>=420){
          posTop[0]+=2;
          bg(arrWid[2],arrHgt[2],posTop[0]);
        }else if(moon.offsetTop>=410){
          posTop[1]+=11;
          bg(arrWid[2],arrHgt[2],posTop[1]);
        }else if(moon.offsetTop>=240){
          posTop[2]+=2;
          bg(arrWid[2],arrHgt[2],posTop[2]);
        }else if(moon.offsetTop>=140){
          posTop[3]+=0.4;
          //月亮即将完全升起时开始改变它的大小(影)
        if(moon.offsetTop<=260&&moon.offsetTop>=140){
          arrWid[2]-=4;
          arrHgt[2]-=1;
          bg(arrWid[2],arrHgt[2],posTop[3]);
        }
        }else{
          bg(284,190,50);
          clearInterval(timer);
          var a=document.createElement("div");
          a.className="Ocean";
          moon.appendChild(a);
          moon.innerHTML+="<img id='girl' src='images/1.png'>";
          var girl=document.getElementById("girl");
          girl.style.animation="appear 6s linear";
          word(Ocean[0],500,poem1);
          var timeOut=setTimeout(function() {
          var div=document.createElement("div");
          div.className="thisTime";
          moon.appendChild(div);
          var thisTime=document.getElementsByClassName("thisTime");
          word(thisTime[0],500,poem2);
          clearTimeout(timeOut);
          }, 2500);
        } 
         },100);
         
          createStar(40,".stars","star",1,300,360,-100);
          createStar(40,".starUnder","star1",1.5,360,300,200);
      //修改倒影
      function bg(widSpd,hgtSpd,posTop){
        return water.style.background="radial-gradient("+widSpd+"px "+hgtSpd+"px at 50.5% "+posTop+"%,rgb(250, 250, 249) 50%,rgb(247, 247, 245) 63%,rgb(7,7,70) 70%,rgb(18, 2, 56) 85%,rgb(13, 1, 59) 100%)" ;
      };
      //制造星星
      function createStar(starNum,element,element2,scal,deg,rotY,rotX){
      var stars=starNum;
      var $stars=$(element);
      var r=2000;
      for(var i=0;i<stars;i++){
        var $star=$("<div/>").addClass(element2);
        $stars.append($star);
        }
      $("."+element2).each(function(){
        var cur=$(this);
        var s=0.2+(Math.random()*scal);
        var curR=r+(Math.random()*deg);
        cur.css({ 
          transformOrigin:"0 0 "+curR+"px",
          transform:" translate3d(0,0,-"+curR+"px) rotateY("+(Math.random()*rotY)+"deg) rotateX("+(Math.random()*rotX)+"deg) rotateY("+-10+"deg) scale("+s+","+s+")"})
          })
      }
      //字
      function word(className,dur,array){
          var i=0;
          var timeName=setInterval(function(){
          className.style.animation="appear 4s linear";
          var p=document.createElement("p");
          p.innerHTML=array[i];
          className.appendChild(p);
          i++;
          if(i>=array.length){
          clearInterval(timeName);
          }
        },dur);
      }
        
          })        
      </script>
</body>
</html>

3,style.css样式代码

@charset "utf-8";
html,body{
  padding: 0px;
  margin: 0px;
  overflow: hidden;
}
#bg{
  height: 100vh;
  width: auto;
  background: radial-gradient(150% 95% at bottom center,rgb(67, 19, 122) 20%,rgb(6,6,70) 55%,rgb(7,7,70) 70%,rgb(18, 2, 56) 85%,rgb(5, 1, 22) 100%);
  overflow: hidden;
  z-index: 1;
}
#water{
  position: relative;
  top: 70vh;
  height: 30vh;
  width: auto;
  z-index:2;

  box-shadow: 0 0 20px rgba(221,225,222,0.9);
}
#moon{
  height: 400px;
  width: 400px;
  background-color:rgb(250, 246, 227);
  border-radius: 50%;
  z-index: 1;
  position: absolute;
  left: 40%;
  font-family: cursive;
  box-shadow: 0 0 50px rgba(251,255, 254, 2);
}
@keyframes rotate {
  0% {
    transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(0);
  }
  100% {
    transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(-360deg);
  }
}
.stars,.starUnder{
  transform: perspective(500px);
  transform-style: preserve-3d;
  position: absolute;
  bottom: 0;
  perspective-origin: 50% 100%;
  left: 50%;
  animation: rotate 270s infinite linear;
}
.star,.star1 {
  width: 2px;
  height: 2px;
  background: rgb(247, 204, 232);
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0 -300px;
  transform: translate3d(0, 0, -300px);
  backface-visibility: hidden;
}
.star1{

  background-color: aliceblue;
  box-shadow:0 0 10px rgb(221,225,222);
}
#girl{
  width: 150px;
  height: 150px;
  position: absolute;
  left: 64%;
  top: 28%;
  z-index: 3;
}
.thisTime{
  position: absolute;
  font-family: cursive;
  top: 8%;
  left: 50%;
}
.Ocean{
  position: absolute;
  left: 30%;
  top: 0%;
}
.thisTime,.Ocean p{
  font-size:34px;
  font-weight: bold;
  position: relative; 
}
@keyframes appear {
  0%{opacity: 0;}
  100%{opacity: 1;}
}

4,素材图

在这里插入图片描述

5,js脚本

js脚本就不这里粘贴了,由于js脚本我们是使用jquery,大家可以通过互联网使用CDN或者去网上下载保存都可以

百度CDN下载地址:https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js

五,结语

以上就是我们今天的教程,如果你觉得博主写的还不错的话,可以关注一下博主,欢迎关注点赞,分享给您身边的朋友。您的鼓励就是对我的最大动力。

转载请注明出处或者链接地址:https://www.qianduange.cn//article/8950.html
标签
节日
评论
会员中心 联系我 留言建议 回顶部
复制成功!