在父悬停时更改子动画/过渡

编程入门 行业动态 更新时间:2024-10-25 20:21:02
本文介绍了在父悬停时更改子动画/过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在努力实现的目标:
我试图在悬停父级时更改子级 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/yb1LrL5o/

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

更多推荐

[db:关键词]

本文发布于:2023-04-26 12:33:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1135387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动画

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!