TweenMax悬停不触发动画

时间:2018-11-07 06:06:54

标签: javascript jquery tweenmax

我正在尝试使用鼠标悬停在另一个div中的链接上来更改带有边框的div的宽度,但是悬停不会将宽度恢复为0。

function over(){
  TweenMax.to($(".grid-item-20"), 1, {
        width: "50%",
        ease: Expo.easeInOut
  });
};

function out(){
  TweenMax.to($("grid-item-20"), 1, {
        width: "0",
        ease: Expo.easeInOut,
  });
};

$(".grid-item-17 a").hover(over, out);
.grid-item-20 {
  border-bottom: 1px solid #000;
  width: 0%;
}
<div class="grid-item-17">

  <a href="#">Home</a>

</div>


<div class="grid-item-20">

</div>

1 个答案:

答案 0 :(得分:1)

您在选择器上缺少dot

function out(){
  TweenMax.to($(".grid-item-20"), 1, {
        width: "0",
        ease: Expo.easeInOut,
  });
};

function over(){
  TweenMax.to($(".grid-item-20"), 1, {
        width: "50%",
        ease: Expo.easeInOut
  });
};

function out(){
  TweenMax.to($(".grid-item-20"), 1, {
        width: "0",
        ease: Expo.easeInOut,
  });
};

$(".grid-item-17 a").hover(over, out);
.grid-item-20 {
  border-bottom: 1px solid #000;
  width: 0%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.1/TweenMax.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="grid-item-17">

  <a href="#">Home</a>

</div>


<div class="grid-item-20">

</div>