[英]Generating keyframes using Javascript/Jquery in React
I'm working on an animation in a react project.我正在 React 项目中制作动画。 The animation includes multiple bubble
s.动画包括多个bubble
。
Each bubble needs to grow and shrink rapidly, my css animation would look like this每个气泡都需要快速增长和缩小,我的 css 动画看起来像这样
@keyframes bubbleTwitch {
0% {
width: 200px;
height: 200px;
}
50% {
width: 150px;
height: 150px;
}
100% {
width: 200px;
height: 200px;
}
}
Then I would repeat it infinitely, at a very short duration然后我会在很短的时间内无限重复
.bubble {
animation-name:bubbleTwitch;
animation-duration:150;
animation-iteration-count:infinite;
}
But the problem is each bubble is a different size.但问题是每个气泡的大小都不同。 I would use transform:scale()
but I am already using transform
for particular translate
ing that is specific to each bubble.我会使用transform:scale()
但我已经在使用transform
来进行特定于每个气泡的特定translate
。
I need a way to generate the keyframes for each bubble in javascript, so that I can tune it to each bubble's size.我需要一种在 javascript 中为每个气泡生成关键帧的方法,以便我可以将其调整为每个气泡的大小。 Or, if there is a way to maintain my original translate
positions, I could simply create a css animation to accomplish this using transform:scale
.或者,如果有一种方法可以保持我的原始translate
位置,我可以简单地创建一个 css 动画来使用transform:scale
来完成此操作。
Anyone know a good way around this?有人知道解决这个问题的好方法吗?
You can fixate the size of each bubble onto an outer div by having the bubble's size change as a percentage.您可以通过将气泡的大小更改为百分比来将每个气泡的大小固定到外部 div 上。 Your jsx might look something like:您的 jsx 可能类似于:
<div className={s.bubbleContainer}>
<div className={bubble} />
</div>
Then the css can be styled as follows:然后可以将 css 样式设置为:
.bubbleContainer {
width: 200px;
height: 200px;
}
@keyframes bubbleTwitch {
0% {
width: 100%;
height: 100%;
}
50% {
width: 75%;
height: 75%;
}
100% {
width: 100%;
height: 100%;
}
}
This way, you can set each individual bubbleContainer to have different sizes with a class in a similar manner to how you planned on doing it with transform:scale.这样,您可以将每个单独的bubbleContainer 设置为具有不同大小的类,其方式与您计划使用transform:scale 的方式类似。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.