首页 > 解决方案 > 如何为移动视图设置悬停动画?

问题描述

我在这里是全新的,所以我希望我的问题是有道理的。我需要为我的图像调整悬停系统。我有 2 个 - 正面和背面。当用户在前面悬停(点击移动设备)时,它应该显示背面。当光标离开元素时,它应该再次显示前面。

这在移动设备上不起作用。当用户点击正面时,背面会出现,但随后他/她必须点击元素外部才能再次显示正面。

如何使用户可以继续单击图像元素以显示正面然后显示背面?

这是我的代码:

.flip-card {
  background-color: transparent;
  width: auto;
  height: auto;
 
  perspective: 1000px; 
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.8s;
  transform-style: preserve-3d;
}

.flip-card:hover .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front, .flip-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden; /* Safari */
  backface-visibility: hidden;
}

.flip-card-front {
  background-color: #bbb;
  color: black;
}

.flip-card-back {
  background-color: dodgerblue;
  color: white;
  transform: rotateY(180deg);
}
<div class="flip-card">
  <div class="flip-card-inner">
    <div class="flip-card-front">
      <img src="https://petlifetoday.com/wp-content/uploads/2019/07/new-kitten-750x500.jpg" alt="Avatar" >
    </div>
    <div class="flip-card-back">
      <img src="https://i.pinimg.com/originals/52/73/c8/5273c86755b215c1f3b4fac7bbad935c.jpg" alt="Avatar" >
    </div>
  </div>
</div>

谢谢

标签: htmlcsshover

解决方案


:focus在您设置的地方使用:hover

文档:https ://developer.mozilla.org/en-US/docs/Web/CSS/:focus


推荐阅读