纯H5+CSS3实现下雨特效

下面这是效果图 :

 HTML部分代码:

为方便大家复制:

        <div class="container">
            <div class="rain">
                <span style="--speed:11"></span>
                <span style="--speed:12"></span>
                <span style="--speed:15"></span>
                <span style="--speed:17"></span>
                <span style="--speed:18"></span>
                <span style="--speed:13"></span>
                <span style="--speed:15"></span>
                <span style="--speed:19"></span>
                <span style="--speed:20"></span>
                <span style="--speed:10"></span>
                <span style="--speed:18"></span>
                <span style="--speed:16"></span>
                <span style="--speed:14"></span>
                <span style="--speed:11"></span>
                <span style="--speed:12"></span>
                <span style="--speed:17"></span>
                <span style="--speed:14"></span>
                <span style="--speed:27"></span>
                <span style="--speed:12"></span>
                
            </div> 

CSS3部分代码:

为了大家方便复制:

body{
    background-color: #212121;
/*     display: flex意思是弹性布局, */
    display: flex;
    /* justify-content是水平布局  项目在水平方向上居中 */
    justify-content: center;
    /* 设置垂直方向对齐方式 */
    align-items: center;
    width: 100%; 
    /* 1vh=浏览器视窗的1% */
    height: 90vh;
}
/* 云的底座第一部分 */
.container{
    position: relative;
    width: 100px;height: 30px;
    background-color: #fff;
    border-radius: 100px;
}
.container::before{
    content:'';
    position: absolute;
    top: -20px;
    left: 10px;
    width: 30px;
    height: 30px;
    background: #fff;
    border-radius: 50%;
    /* 利用盒子阴影制作右边云彩 */
    box-shadow: 40px 0 0 20px #fff;
}
.rain{
    position: relative;
    display: flex;
    z-index: 1;
}
.rain span{
    position: relative;
    width: 8px;height: 8px;
    background: #fff;
    margin: 10px 2px;
    border-radius: 50%;
    /* 动画匀速运行 且自动循环 */
    animation: rain linear infinite;
    /* 设置下雨的速度 */
    animation-duration: calc(15s/var(--speed));
    /* 原点位置 */
    transform-origin:bottom;
}
@keyframes rain{
    0%{
        transform: translateY(0);
    }
    70%{
        transform: translateY(100px) scale(1);
    }

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


    

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个基本的搜索框下拉列表的实现步骤: 1. HTML结构:在HTML中创建一个输入框和一个下拉列表的容器,下拉列表的容器初始设置为隐藏状态。 ```html <div class="search-container"> <input type="text" placeholder="请输入搜索关键字"> <div class="search-list-container"> <ul class="search-list"></ul> </div> </div> ``` 2. CSS样式:设置输入框的样式和下拉列表容器的样式,下拉列表容器的初始状态设置为 `display:none` 。 ```css .search-container { position: relative; } input[type="text"] { width: 300px; height: 30px; padding: 5px; border: 1px solid #ccc; border-radius: 5px; } .search-list-container { position: absolute; top: 35px; left: 0; z-index: 99; width: 300px; max-height: 200px; overflow-y: auto; background: #fff; border: 1px solid #ccc; border-radius: 5px; display: none; } ``` 3. JS交互:监听输入框的键盘输入事件,在输入框中输入内容时,向后台发送请求获取匹配的搜索结果,将结果渲染到下拉列表中,并将下拉列表容器设置为显示状态。 ```javascript const input = document.querySelector('input[type="text"]'); const searchListContainer = document.querySelector('.search-list-container'); const searchList = document.querySelector('.search-list'); input.addEventListener('input', function(e) { const keyword = e.target.value; if (keyword.trim()) { // 发送请求获取匹配的搜索结果 const searchResults = getSearchResults(keyword); renderSearchList(searchResults); searchListContainer.style.display = 'block'; } else { searchList.innerHTML = ''; searchListContainer.style.display = 'none'; } }); function getSearchResults(keyword) { // 向后台发送请求获取搜索结果 const results = ['搜索结果1', '搜索结果2', '搜索结果3']; return results; } function renderSearchList(results) { let html = ''; results.forEach(result => { html += `<li>${result}</li>`; }); searchList.innerHTML = html; } ``` 以上就是一个简单的搜索框下拉列表的实现方法,您可以根据自己的需求进行样式和交互的修改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值