我有一些纯HTML/CSS代码需要解决 -
当鼠标悬停在卡片上时,应该会出现翻转效果。 这个效果是有效的,但如果你在太快或奇怪的角度上运行它,它会产生一种“卡顿”的感觉。 我正在尝试修复它,使其无论如何都能无缝。
似乎问题发生在光标超出卡片容器范围时,因为盒子正在收缩和再次扩展以创建翻转效果。
有什么办法可以解决吗?
https://codepen.io/mttmrn/pen/zgZKjj
HTML:
<body>
<!--
This is where the cards start
-->
<div class="card-container">
<div class="card">
<div class="card-front">
<img src="./img/cool-background.png" alt="background" class="card-img">
<ul class="card-text">
<li>React | Redux</li>
<li>NodeJS</li>
<li>JavaScript</li>
</ul>
</div>
<div class="card-back">
<ul class="card-text">
<li>hello</li>
<li>twice</li>
</ul>
</div>
CSS:
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
font-family: "Poppins", sans-serif;
background: rgb(250, 224, 30);
}
.card-container {
display: flex;
margin-top: 12%;
margin-left: 15%;
margin-right: 15%;
justify-content: space-evenly;
text-align: center;
flex-wrap: wrap;
}
.card {
width: 275px;
height: 350px;
border: 4px solid black;
margin-top: 50px;
border-radius: 2px;
-webkit-box-shadow: 4px 4px 10px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 4px 4px 10px 0px rgba(0, 0, 0, 0.75);
box-shadow: 3px 3px 6px 0px rgba(0, 0, 0, 0.75);
transform-style: preserve-3d;
transition: transform 1s;
}
.card:hover {
transform: rotateY(180deg);
}
.card-front {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
transform: rotateY(180deg);
}
.card-back {
background: wheat;
}
.card-text {
list-style: none;
margin: 20px 50px 0px 50px;
line-height: 40px;
}
.card-text li:not(:last-child) {
border-bottom: 1px solid #0004;
}
.card-img {
height: 150px;
width: 268px;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 68%, 0 100%);
clip-path: polygon(0 0, 100% 0, 100% 68%, 0 100%);
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.card-front:nth-child(1) {
animation: fadeIn 1.5s 0.3s backwards;
}
.card-front:nth-child(2) {
animation: fadeIn 1.5s 0.6s backwards;
}
.card-front:nth-child(3) {
animation: fadeIn 1.5s 0.9s backwards;
}
.card-front:nth-child(4) {
animation: fadeIn 2s 1.2s backwards;
}
.card-front:nth-child(5) {
animation: fadeIn 2s 1.5s backwards;
}
.card-front:nth-child(6) {
animation: fadeIn 2s 1.8s backwards;
}
鼠标悬停时动画应平滑进行,并且在光标离开卡片之前应保持翻转状态。