jquery - 在信息图标悬停时翻转卡片 - Tweenmax

标签 jquery css gsap

这是我的 fiddle :DEMO

将鼠标悬停在卡片上会翻转卡片。如何在悬停在“信息”图标上时翻转卡片?

$(".cardWrapper").hover(
  function() {
    TweenLite.to($(this).find(".card"), 1.2, {
      rotationY: 180,
      ease: Back.easeOut
    });
  },
  function() {
    TweenLite.to($(this).find(".card"), 1.2, {
      rotationY: 0,
      ease: Back.easeOut
    });
  }
);

最佳答案

要完成这项工作,您需要将选择器更改为 .cardWrapper .info 并将 find() 更改为 closest()

您还必须将悬停进/出事件分开,否则翻转将立即发生,因为 .info 在翻转时不再“悬停”。像这样:

$(".cardWrapper .info").mouseenter(function() {
  TweenLite.to($(this).closest(".card"), 1.2, {
    rotationY: 180,
    ease: Back.easeOut
  });
});

$(".cardWrapper").mouseleave(function() {
  TweenLite.to($(this).find(".card"), 1.2, {
    rotationY: 0,
    ease: Back.easeOut
  });
});

TweenLite.set(".cardWrapper", {
  perspective: 800
});
TweenLite.set(".card", {
  transformStyle: "preserve-3d"
});
TweenLite.set(".back", {
  rotationY: -180
});
TweenLite.set([".back", ".front"], {
  backfaceVisibility: "hidden"
});

$(".cardWrapper .info").mouseenter(function() {
  TweenLite.to($(this).closest(".card"), 1.2, {
    rotationY: 180,
    ease: Back.easeOut
  });
});

$(".cardWrapper").mouseleave(function() {
  TweenLite.to($(this).find(".card"), 1.2, {
    rotationY: 0,
    ease: Back.easeOut
  });
});


TweenMax.staggerTo($(".card"), 1, {
  rotationY: -180,
  repeat: 1,
  yoyo: true
}, 0.1);
body {
  background-color: black;
  margin: 20px;
  font-family: Arial, sans-serif;
}

.cardWrapper {
  width: 200px;
  height: 200px;
  position: relative;
  /*background-color:#333;*/
  float: left;
  margin-right: 10px;
  cursor: pointer;
  -webkit-font-smoothing: antialiased;
}

.cardFace {
  position: absolute;
  width: 200px;
  height: 200px;
  overflow: hidden;
}

.front {
  background-color: #333;
}

.back {
  background-color: #333;
}

.cardFace h1 {
  margin: 0px;
  font-size: 30px;
  padding: 10px 0px 10px 10px;
  border-bottom: solid 6px #aaa;
  border-top: solid 6px #aaa;
  background-color: black;
  color: white;
}

.cardFace.back h1 {
  border-color: #91e600;
}

.moreInfo {
  padding: 10px;
  color: white;
  line-height: 24px;
}

.info {
  font-size: 24px;
  color: #fff;
  font-weight: bold;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.4/TweenMax.min.js"></script>
<div class="cardWrapper">
  <div class="card">
    <div class="cardFace front">
      <h1>front</h1>
      <div class="info">&#9432;</div>
    </div>
    <div class="cardFace back">
      <h1>back</h1>
    </div>
  </div>
</div>

<div class="cardWrapper">
  <div class="card">
    <div class="cardFace front">
      <h1>front</h1>
      <div class="info">&#9432;</div>
    </div>
    <div class="cardFace back">
      <h1>back</h1>
    </div>
  </div>
</div>

<div class="cardWrapper">
  <div class="card">
    <div class="cardFace front"><img src="https://s.cdpn.io/16327/logo_texture.jpg"></div>
    <div class="cardFace back"><img src="https://s.cdpn.io/16327/logo_robust.jpg"></div>
  </div>
</div>

<div class="cardWrapper">
  <div class="card">
    <div class="cardFace front">
      <h1>front</h1>
      <div class="info">&#9432;</div>
    </div>
    <div class="cardFace back">
      <h1>back</h1>
    </div>
  </div>
</div>

<div class="cardWrapper">
  <div class="card">
    <div class="cardFace front">
      <h1>front</h1>
      <div class="info">&#9432;</div>
    </div>
    <div class="cardFace back">
      <div class="moreInfo">This is just an example of how you can customize the content of any card face.</div>
    </div>
  </div>
</div>

关于jquery - 在信息图标悬停时翻转卡片 - Tweenmax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46562941/

相关文章:

jquery - 如何获取所选数据列表项的数据值属性的值

javascript - CSS:如何在每次悬停时不重置悬停动画

javascript - 如何让方法使用参数调用自身而不发生堆栈溢出

javascript - GreenSock,补间函数参数

javascript - 鼠标悬停时创建圆形火焰效果

javascript - Bootstrap 3 和 ScrollTop 函数 : #link conflict

javascript - 使用 jQuery 删除表数据

jquery - Bootstrap V4 模态效果背景不稳定

jquery - 为什么这个关键帧动画不起作用?

html - 用作背景的 spritesheet 图像填充容器