[CSS] Create a Card Flip Animation with CSS
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了[CSS] Create a Card Flip Animation with CSS,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2182字,纯文字阅读大概需要4分钟。
内容图文
![[CSS] Create a Card Flip Animation with CSS](/upload/InfoBanner/zyjiaocheng/1158/192314fd4eda433591ba479bd6edc60a.jpg)
Animation can be a powerful way to enhance a user experience. In this lesson, we‘ll walk through the creation of a card-flip animation, creating a nice visual effect when toggling between the front and back of a div meant to represent a card, like a playing card, or a flashcard. We‘ll create this effect using a touch of JavaScript and CSS transforms. No framework or library required.
.container { display: flex; flex-direction: column; align-items: center; width: 50vw; margin: auto; } .card { margin-top: 1rem; height: 60vh; width: 100%; position: relative; } .cardFront, .cardBack { border-radius: 0.25rem; height: 100%; padding-left: 0.5rem; padding-right: 0.5rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); width: 100%; position: absolute; backface-visibility: hidden; transition: transform 0.5s ease; } .cardBack { transform: perspective(600px) rotateY(180deg); background-color: #ebf4ff; } .cardBack.flipped { transform: perspective(600px) rotateY(0deg); } .cardFront { transform: perspective(600px) rotateY(0deg); } .cardFront.flipped { transform: perspective(600px) rotateY(-180deg); }
<! DOCTYPE html > < html lang ="en" > < head > < meta charset ="UTF-8" /> < meta name ="viewport" content ="width=device-width, initial-scale=1.0" /> < meta http-equiv ="X-UA-Compatible" content ="ie=edge" /> < title >CSS Card Flip</title><link rel="stylesheet" href="./styles.css"/></head><body><div class="container"><button type="button" id="flip-btn">Flip Card</button><div class="card"><div id="back" class="cardBack">Back</div><div id="front" class="cardFront">Front</div></div></div><script> const front = document.getElementById(‘front‘) const back = document.getElementById(‘back‘) const btn = document.getElementById(‘flip-btn‘) function handleFlip() { front.classList.toggle(‘flipped‘) back.classList.toggle(‘flipped‘) } btn.addEventListener(‘click‘, handleFlip) </script></body></html>
原文:https://www.cnblogs.com/Answer1215/p/11779470.html
内容总结
以上是互联网集市为您收集整理的[CSS] Create a Card Flip Animation with CSS全部内容,希望文章能够帮你解决[CSS] Create a Card Flip Animation with CSS所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。