HTML CSS下雨效果

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* 不会挤大盒子 */
}

body {
    width: 100%;
    height: 100vh;
    /* Vh:1vh 等于视口高度的1% */
    background-color: #2b2b2b;
    display: flex;
}

.cloud {
    width: 320px;
    height: 80px;
    background-color: #b0aaaa;
    border-radius: 50px;
    margin: auto;
    position: relative;
}

/* 模拟地面 */
.cloud::after {
    content: '';
    width: 100%;
    height: 10px;
    background-color: #b0aaaa;
    position: absolute;
    bottom: -150px;
    border-radius: 50%;
}

.clouds {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background-color: #b0aaaa;
    position: absolute;
    top: -50px;
    left: 50px;
}

/* 右上角云朵 */
.clouds::after {
    content: '';
    width: 130px;
    height: 130px;
    position: absolute;
    background-color: #b0aaaa;
    left: 80px;
    top: -30px;
    border-radius: 50%;
}

.rain {
    width: 100%;
    display: flex;
    position: absolute;
    /* 定义雨滴样子 */
    top: 50%;
    left: 50px;
    /* 调整雨滴开始的位置 */
    transform: translate();
}

.rain span {
    width: 15px;
    height: 15px;
    background: #fff;
    margin: 0 5px;
    border-radius: 50%;
    /* 雨滴是一直线 使其分开 */
    animation: animate linear 2s infinite;
    animation-duration: calc(var(--i) * 2s);
    /*  animation-duration属性指定一个动画周期的时长 */
}

@keyframes animate {
    0% {
        transform: translateY(0)scale(0);
        /* scale(x,y)用于修改元素的大小 */
    }

    100% {
        transform: translateY(170px)scale(1);
    }
}




    
    
    
    Document
    




    

JS

// 创建雨滴
for (let i = 0; i < 10; i++) {
    let rains = document.createElement("span")
    rains.style = `--i:${Math.random()}`;
    rain.append(rains)
}

HTML CSS下雨效果_第1张图片

非本人创作,及作为存储回顾

原作者:Html,css下雨效果_哔哩哔哩_bilibili

作者的git仓库:https://gitee.com/rgbh/htmlcssdemon

你可能感兴趣的:(css,html,css3)