纯css实现图片带倒影效果的hover翻转特效

1 篇文章 0 订阅

效果图:

 

<template>
  <div class="glassReflection">
    <div class="scene">
      <div class="card">
        <div class="showCard showCardFront">
          <img src="../showFiles/3.png" />
        </div>
        <div class="showCard showCardBack">
          <img src="../showFiles/2.jpg" />
        </div>
      </div>
      <div class="card">
        <div class="showCard showCardFront">
          <img src="../showFiles/4.jpg" />
        </div>
        <div class="showCard showCardBack">
          <img src="../showFiles/5.jpg" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {};
</script>

<style scoped>
.glassReflection {
  width: 60%;
  height: 95%;
  margin: 1%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
}
.scene {
  width: 90%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  /* perspective: 800px; */
}
.card {
  position: relative;
  width: 15rem;
  height: 16rem;
  color: white;
  cursor: pointer;
  transition: 1s ease-in-out;
  transform-style: preserve-3d;
}
/* 固定宽高的父元素触发,子元素翻转,如果直接对元素hover触发,元素翻转过程中,
元素区域变小,光标很有可能就脱离元素,造成不顺畅 */

.card:hover .showCardFront {
  transform: rotateY(0.5turn);
}
.card:hover .showCardBack {
  transform: rotateY(0);
}
.showCard {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  transition: 1s ease-in-out;
  /* 倒影(-webkit-box-reflect)属性值有:dirrection-方向:above向上,below向下,left向左,right向右。
  offset距离:可以是数值,也可以是百分比 */
  -webkit-box-reflect: below 0
    linear-gradient(transparent, transparent, rgba(0, 0, 0, 0.4));
}
img {
  width: 15rem;
  height: 16rem;
  -o-object-fit: cover;
  object-fit: cover;
}
.showCardBack {
  transform: rotateY(0.5turn);
}
</style>

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值