【问题标题】:Reversing a Keyframe Animation on Hover Out在悬停时反转关键帧动画
【发布时间】:2014-12-31 02:04:31
【问题描述】:

这是一个演示:

http://codepen.io/Tiger0915/pen/GgjVLN

我在.circle div 的hover 上有一个keyframe 动画。当您将鼠标悬停在它上面时,它可以正常工作。

@include keyframes(bounce-bulge) {
  0% {
    transform: scale(1);
  }
  20% {
    transform: scale(.75);
  }
  80% {
    transform: scale(1.75);
  }
  100% {
    transform: scale(1.5);
  }
}


.circle {
  transition: all 300ms ease;

  &:hover {
    @include animation(bounce-bulge 500ms forwards);
  }
}

每当您停止将鼠标悬停在元素上时,我想反转 keyframe 的效果。

仅使用 CSS 是否可行?

【问题讨论】:

    标签: css sass css-animations keyframe compass


    【解决方案1】:

    看看我的例子,如果这是你想要的(有人会发明更优雅的解决方案)

    http://codepen.io/Mardzis/pen/YPGmmq

    CSS(SASS):

    @include keyframes(bounce-bulge) {
      0% {
        transform: scale(1);
      }
      20% {
        transform: scale(.75);
      }
      80% {
        transform: scale(1.75);
      }
      100% {
        transform: scale(1.5);
      }
    }
    
    @include keyframes(bounce-bulge-back) {
      100% {
        transform: scale(1);
      }
      80% {
        transform: scale(.75);
      }
      20% {
        transform: scale(1.75);
      }
      0% {
        transform: scale(1.5);
      }
    }
    
    
    .circle {
      margin: 100px auto 0;
      width: 30px;
      height: 30px;
    
      border: 10px solid blue;
      border-radius: 50%;
      background: lightblue;
      cursor: pointer;
    
      transition: all 300ms ease;
      @include animation(bounce-bulge-back 500ms forwards);
    
      &:hover {
        @include animation(bounce-bulge 500ms forwards);
      }
    }
    

    【讨论】:

    • 这是一个很好的解决方案。有什么办法可以防止它在页面加载时发生?
    • 我遇到了这个并且有同样的问题......想知道如何在页面加载时防止它......因为这也是我面临的问题
    • 你可以在你的游戏状态developer.mozilla.org/en-US/docs/Web/CSS/animation-play-state 和 javascript 玩
    • 或者只在第一次悬停后使用Javascript添加反向动画。
    猜你喜欢
    • 2014-11-19
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 2018-03-09
    • 2016-05-13
    • 2015-04-05
    • 2019-09-28
    • 2021-11-13
    相关资源
    最近更新 更多