If you want to grow, get outside
your comfort zone.
CSS100Day(26)-激励卡片切换
812 字
4 分钟
CSS100Day(26)-激励卡片切换
设计简介
关键点如下
- 知识点1:没有什么知识点,注意动画的实现,分别两个进入一个退出一个,通过
active和inactive类样式
效果展示
1
The couch
2
Failing is learning
Pick yourself up, dust yourself off, and start again.
3
Flowers and rainbows
Always be yourself,
unless you can be a unicorn.
实现代码和步骤
HTML部分
<div class="frame"> <div class="card active"> <div class="number-bg"></div> <div class="number">1</div> <div class="text"> <span class="headline">The couch</span> <p> If you want to grow, get outside<br /> your comfort zone. </p> </div> <div class="button">切换</div> </div> <div class="card"> <div class="number-bg"></div> <div class="number">2</div> <div class="text"> <span class="headline">Failing is learning</span> <p>Pick yourself up, dust yourself off, and start again.</p> </div> <div class="button">切换</div> </div> <div class="card"> <div class="number-bg"></div> <div class="number">3</div> <div class="text"> <span class="headline">Flowers and rainbows</span> <p> Always be yourself,<br /> unless you can be a unicorn. </p> </div> <div class="button">切换</div> </div></div>CSS部分
.frame { box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3); width: 400px; height: 400px; border-radius: 2px; background: #c7d6e1; overflow: hidden; display: grid; place-content: center;}.card { pointer-events: none; background: #fff; border-radius: 2px; width: 240px; height: 150px; position: absolute; top: 125px; left: 80px; box-shadow: 4px 8px 12px 0 rgba(0, 0, 0, 0.2); opacity: 0; overflow: hidden; &.active { pointer-events: all; z-index: 1; animation: fadeIn 0.6s ease-in-out both 0.5s; } &.inactive { pointer-events: none; z-index: 2; animation: fadeOut 0.5s ease-in-out both; } .number-bg { position: absolute; width: 60px; height: 60px; top: -31px; right: -31px; background: #8391a1; transform: rotate(45deg); } .number { position: absolute; top: 6px; right: 8px; font-size: 13px; line-height: 13px; font-weight: 600; color: #fff; } .text { text-align: center; padding: 20px 10px; .headline { display: block; font-size: 14px; line-height: 22px; font-weight: 600; color: #616e7d; margin-bottom: 8px; }
p { font-size: 12px; line-height: 17px; color: #8391a1; margin: 0; } } .button { position: absolute; width: 100%; height: 40px; bottom: 0; left: 0; right: 0; background: #3ca7fb; cursor: pointer; text-align: center; text-transform: uppercase; line-height: 38px; font-size: 13px; color: #fff; transition: all 0.3s ease-in-out; &:hover { background: #2196f3; } }}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); }}@keyframes fadeOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(1.15); }}JS部分
<script> let active = 1 const buttons = document.querySelectorAll(".button") buttons.forEach(function (button){" "} {button.addEventListener("click", function () { var currentCard = document.querySelector(".card:nth-child(" + active + ")") if (currentCard) { currentCard.classList.remove("active") currentCard.classList.add("inactive") } if (active === 3) { active = 0 } active++ var nextCard = document.querySelector(".card:nth-child(" + active + ")") if (nextCard) { nextCard.classList.remove("inactive") nextCard.classList.add("active") } })} )</script>分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接
相关文章
推荐筛选
1
CSS100Day(14)-3D卡片翻转
设计灵感 一个3D卡片翻转原理理解
2
CSS100Day(6)-卡片练习和绝对定位圆圈
设计灵感 头像外两个嵌套圆圈绝对定位技巧,以及利用filter实现hover加深
3
CSS100Day(28)-振铃动画
设计灵感 振铃动画
4
CSS100Day(24)-一个按钮动画
设计灵感 依然使用svg-dasharray转圈,使用checkbutton实现点击动画加载
5
CSS100Day(23)-动态字体动画设计
设计灵感 线段的动画设计,以及文字隐藏出现的设计
随机文章
随机推荐