为了账号安全,请及时绑定邮箱和手机立即绑定

为什么在此 CSS 转换过程中存在明显的滞后?

为什么在此 CSS 转换过程中存在明显的滞后?

长风秋雁 2023-10-30 20:59:09
该 html 元素的转换在第一次运行时有明显的滞后。当您将鼠标悬停在其上多次后,这种卡片翻转机制会很顺畅。有人可以解释为什么以及如何解决它吗?.container {  display: flex;  flex-wrap: wrap;  justify-content: center;}.k-card {  border-radius: 25px;  width: 250px;  margin: 2%;  border-color: white;  height: 330px;}.k-card-image {  text-align: center;  align-content: center;}.k-card-footer {  text-align: center;  border: none;  position: absolute;  bottom: 1px;  width: 100%;  background-color: inherit;  font-weight: bold;  color: white;  align-items: center;  border-radius: 25px;}/* The flip card container - set the width and height to whatever you want. We have added the border property to demonstrate that the flip itself goes out of the box on hover (remove perspective if you don't want the 3D effect */.flip-card {  border-radius: 25px;  width: 250px;  height: 330px;}/* This container is needed to position the front and back side */.flip-card-inner {  border-radius: 25px;  position: relative;  width: 100%;  height: 100%;  text-align: center;  transition: transform 0.5s;  transform-style: preserve-3d;}/* Do an horizontal flip when you move the mouse over the flip box container */.flip-card:hover .flip-card-inner {  transform: rotateY(180deg);}/* Position the front and back side */.flip-card-front,.flip-card-back {  position: absolute;  width: 100%;  height: 100%;  -webkit-backface-visibility: hidden;  /* Safari */  backface-visibility: hidden;  border-radius: 25px;}/* Style the front side */.flip-card-front {  background-color: #18988B;}.k-button.k-primary {  background-color: #18988B;  padding: 2px;  border-color: #18988B;}另外,jsfiddle 的链接:https://jsfiddle.net/McRobBlob/s9f07wgy/
查看完整描述

2 回答

?
眼眸繁星

TA贡献1873条经验 获得超9个赞

问题在于财产transform-style: preserve-3d;。


将其从.flip-card-inner方块中移除并将其移至.flip-card:hover .flip-card-inner方块中。


.flip-card-inner {

  border-radius: 25px;

  position: relative;

  width: 100%;

  height: 100%;

  text-align: center;

  transition: transform 0.5s;

/*  transform-style: preserve-3d; remove */

}



/* Do an horizontal flip when you move the mouse over the flip box container */


.flip-card:hover .flip-card-inner {

  transform: rotateY(180deg);

  transform-style: preserve-3d; /* add */

}

更新


在 @TemaniAfif 评论之后我有更好的解决方案:


backface-visibility: hidden;只需从你的 CSS 中删除即可。


.flip-card-front,

.flip-card-back {

/* -webkit-backface-visibility: hidden; remove */

/* backface-visibility: hidden;  remove */

}


查看完整回答
反对 回复 2023-10-30
?
函数式编程

TA贡献1807条经验 获得超9个赞

我会尝试添加will-change: transform;orwill-change: auto;.flip-card-inner.

参考: https://developer.mozilla.org/en-US/docs/Web/CSS/will-change


查看完整回答
反对 回复 2023-10-30
  • 2 回答
  • 0 关注
  • 85 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信