HTML云朵下雨案例

效果:

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>乌云下雨</title>
</head>
<style >
    body{
        background-color: white;
        display: flex;
    }
    .yun{
        margin: auto;
        display: flex;
        width: 100%;
        height: 100vh;

    }
    .WuYun {
        width: 330px;
        height: 80px;
        background-color: #a1a1a1;
        margin: auto;
        border-radius: 50px;
        position: relative;
    }
    .WuYun::after{
        content: '';
        width: 330px;
        height: 6px;
        border-radius: 3px;
        background-color: #a1a1a1;
        position: absolute;
        bottom: -120px;
        left: 0;
    }
    .One{
        background-color: #a1a1a1;
        border-radius: 50%;
        position: absolute;
        z-index: -1;
    }
    .One_A{
        width: 100px;
        height: 100px;
        border-color: red;
        top: -60px;
        left: 10px;
    }
    .One_B{
        width: 150px;
        height: 150px;
        border-color: #42b983;
        top: -110px;
        right: 80px;
    }
    .One_C{
        border-color: yellow;
        width: 90px;
        height: 90px;
        top: -50px;
        right: 15px;
    }
    button{
        position: absolute;
        left: 60%;
        bottom: 200px;
    }
    #but{
        left: 65%;
    }
    .WuYun span{
        width: 10px;
        height: 10px;
        background-color: black;
        display: inline-block;
        margin: 0 13px;
        z-index: 999;
        /* 动画开启 */
       animation-name:xiayu;
       /* 完成时间 */
       animation-duration:calc(var(--RanDom)*4s);
       /* 循环执行 */
       animation-iteration-count:infinite;
       /* 开始时间 */
       animation-delay:-2s;   
    }
    @keyframes xiayu {
        0%{transform: translateY(54px) scale(0);border-radius: 30%;height: 10px;}
        
        100%{transform: translateY(160px)  scale(0.8) ;border-radius: 50%;height: 20px;opacity: 0;}
    }
</style>
<body>
<div class="yun">
    <div class="WuYun">
        <div class="One One_A"></div>
        <div class="One One_B" ></div>
        <div class="One One_C"></div>
    </div>
   <button>点击下雨</button>
   <button id="but">彩色雨</button>
</div>
</body>
<script>
  // 创建雨滴的方法
  function SetRain(){
    let i=0;
    let  MyWuYun=document.getElementsByClassName('WuYun')[0];
    for(i;i<20;i++){
      // 创建span节点
      let Span=document.createElement('span');
      Span.style=`--RanDom:${Math.random()}`;
      // 向父元素里面追加span标签
      MyWuYun.appendChild(Span);    
    }
  };
  // 获取按钮下雨
  let But=document.getElementsByTagName('button'),
      Tag=true;
  // 点击下雨事件
  But[0].onclick=function(){
    if(Tag){
      SetRain()
      Tag=false;
    }else{
      return ;
    } 
  };
  // 彩虹糖
  But[1].onclick=function(){
    for(let i=0;i<document.getElementsByTagName('span').length;i++){
      document.getElementsByTagName('span')[i].style.backgroundColor=`rgb(${Math.random()*100},${Math.random()*100},${Math.random()*100})`
    }
  }
  
</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值