xxx
CSS100Day(15)-上传组件的显示变化
930 字
5 分钟
CSS100Day(15)-上传组件的显示变化
设计简介
本次练习主要练习上传组件,在选择后调整样式,和点击后显示进度条以及svg的动画:
- 知识点1:对于进度条,其实可以使用scaleX(0)到scaleX(1)的过渡,而不需要width过渡
效果展示
拖拽上传
上传文件
实现代码和步骤
HTML部分
HTML部分如下
<div class="frame"> <div class="center"> <div class="title">拖拽上传</div> <div class="bar"></div> <div class="dropZone"> <div class="content"> <img src="https://100dayscss.com/codepen/upload.svg" class="upload" /> <div class="filename">xxx</div> <input type="file" class="input" /> </div> </div> <img src="https://100dayscss.com/codepen/syncing.svg" class="syncing" /> <img src="https://100dayscss.com/codepen/checkmark.svg" class="done" /> <div class="upload-btn">上传文件</div> </div></div>CSS部分
注意2知识点即可
:root { box-sizing: border-box;}
.frame { width: 400px; height: 400px; position: relative; box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3); color: white; border-radius: 2px; background: linear-gradient(to top right, #3a92af 0%, #5ca05a 100%); display: grid; place-content: center;}
.center { width: 300px; height: 260px; background: #fff; display: flex; flex-direction: column; border-radius: 3px; align-items: center; position: relative;
.title { font-size: 16px; color: #676767; text-align: center; height: 50px; line-height: 50px; border-bottom: 1px solid #d8d8d8; width: 100%; }
.bar { position: absolute; width: 300px; height: 3px; top: 49px; left: 0; background: #6ece3b; transform: scaleX(0); transition: all 3s ease-out; transform-origin: 0 0;
&.active { transform: scaleX(1); } }
.dropZone { display: grid; place-content: center; height: 150px;
.content { width: 100px; height: 80px; border: 1px dashed #a4a4a4; position: relative;
.upload, .input-class-chen, .filename { position: absolute; inset: 0; margin: auto; }
.upload { opacity: 1; }
.filename { display: block; color: #676767; font-size: 14px; text-align: center; opacity: 0; display: flex; align-items: center; justify-content: center; }
.input-class-chen { opacity: 0; }
&.selected .upload { opacity: 0; }
&.selected .filename { opacity: 1; }
&.active { opacity: 0; } } }
.syncing, .done { position: absolute; top: 109px; left: 134px; opacity: 0; pointer-events: none; }
.syncing.active { animation: syncing 3.2s ease-in-out; }
.done.active { animation: done 0.5s ease-in 3.2s; animation-fill-mode: both; }
.upload-btn { border-radius: 3px; text-align: center; line-height: 40px; font-size: 14px; box-shadow: 0 2px 0 0 #498c25; cursor: pointer; width: 140px; height: 40px; background: #6ece3b; transition: all 0.2s ease-in-out;
&:hover { box-shadow: 0 2px 0 0 #498c25, 0 2px 10px 0 #6ece3b; } }}
@keyframes syncing { 0% { transform: rotate(0); } 10% { opacity: 1; } 90% { opacity: 1; } 100% { transform: rotate(360deg); opacity: 0; }}
@keyframes done { from { opacity: 0; } to { opacity: 1; }}JS部分
JS就是添加点.selected .active类样式了
const input = document.querySelector(".input")const filenameDiv = document.querySelector(".filename")const contentDiv = document.querySelector(".content")const uploadBtn = document.querySelector(".upload-btn")const uploadImg = document.querySelector(".upload")const bar = document.querySelector(".bar")const syncDiv = document.querySelector(".syncing")const doneDiv = document.querySelector(".done")let isSelect = falseinput.addEventListener("change", (e) => { const filename = e.target.files[0].name filenameDiv.textContent = filename contentDiv.classList.add("selected") isSelect = true})uploadBtn.addEventListener("click", () => { if (isSelect) { bar.classList.add("active") contentDiv.classList.add("active") syncDiv.classList.add("active") doneDiv.classList.add("active") }})分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接
相关文章
推荐筛选
1
CSS100Day(18)-3D实现弹性元素
设计灵感 3D实现弹性元素
2
CSS100Day(17)-svg实现彭罗斯三角
设计灵感 三个svg实现彭罗斯三角
3
CSS100Day(20)-发送邮件惊艳动画无JS
设计灵感 纯css实现发送邮件,利用checkbox
4
CSS100Day(21)-利用svg线段实现吃小球动画
设计灵感 利用svg线段实现吃小球动画
5
CSS100Day(14)-3D卡片翻转
设计灵感 一个3D卡片翻转原理理解
随机文章
随机推荐