在父悬停时更改子动画/过渡 [英] Change child animation/transition on parent hover

查看:39
本文介绍了在父悬停时更改子动画/过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力实现的目标:
我试图在悬停父级时更改子级 CSS 动画.但是,由于某种原因,它不起作用.

What I am trying to achieve:
I am trying to change a child CSS animation when hovering the parent. It is, however, for some reason not working.

解释:
.front-ball 从一开始就应用了 hvr-wobble-vertical.然后我希望动画在悬停其父元素 .wbutton 时更改为 .front-ball 缩放动画.

Explanation:
.front-ball has the hvr-wobble-vertical applied to it from the start. I then want the animation to change to .front-ball scale animation when hovering it's parent element, .wbutton.

HTML:

<a class="wbutton img-responsive center-block" role="button">
  <img class="front-logo" src="img/logos/logowork_03.png" />
  <img class="front-ball" src="img/logos/logowork_09.png" />
</a>

CSS:

.wbutton:hover > .front-ball {
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
}

.front-ball {
  display: inline-block;
  vertical-align: middle;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  -webkit-animation-name: hvr-wobble-vertical;
  animation-name: hvr-wobble-vertical;
  -webkit-transition-property: transform;
  transition-property: transform;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
  -webkit-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
}

@-webkit-keyframes hvr-wobble-vertical {
  16.65% {
    -webkit-transform: translateY(8px);
    transform: translateY(8px);
  }
  33.3% {
    -webkit-transform: translateY(-6px);
    transform: translateY(-6px);
  }
  49.95% {
    -webkit-transform: translateY(4px);
    transform: translateY(4px);
  }
  66.6% {
    -webkit-transform: translateY(-2px);
    transform: translateY(-2px);
  }
  83.25% {
    -webkit-transform: translateY(1px);
    transform: translateY(1px);
  }
  100% {
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
}

@keyframes hvr-wobble-vertical {
  16.65% {
    -webkit-transform: translateY(8px);
    transform: translateY(8px);
  }
  33.3% {
    -webkit-transform: translateY(-6px);
    transform: translateY(-6px);
  }
  49.95% {
    -webkit-transform: translateY(4px);
    transform: translateY(4px);
  }
  66.6% {
    -webkit-transform: translateY(-2px);
    transform: translateY(-2px);
  }
  83.25% {
    -webkit-transform: translateY(1px);
    transform: translateY(1px);
  }
  100% {
    -webkit-transform: translateY(0);
    transform: translateY(0);
  }
}

很明显,我试图一次使用 2 个动画/过渡,但我不知道达到我想要的效果的正确方法是什么.

It is obvious that I am trying to use 2 animations/transitions at a time, but I do not know what the correct way to reach my desired effect is.

推荐答案

您可以制作另一个 keyframes 来处理 scale 动画 并在悬停时替换 hvr-wobble-vertical 与您的新关键帧

You can make another keyframes to handle the scale animation and on hover replace the hvr-wobble-vertical with your new keyframes

.wbutton:hover > .front-ball {
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
  -webkit-animation-name: hve-scale;
  animation-name: hve-scale;
  -webkit-animation-iteration-count: 1;
  animation-iteration-count: 1;
}

@-webkit-keyframes hve-scale {
  0% {
    -webkit-transform: scale(1);
  }
  100% {
    -webkit-transform: scale(1.1);
  }
}

@keyframes hve-scale {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.1);
  }
}

演示:https://jsfiddle.net/yb1LrL5o/

这篇关于在父悬停时更改子动画/过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆