如何定位由Lottie动画创建的SVG元素?

发布于 2025-02-05 15:27:44 字数 517 浏览 0 评论 0原文

我试图针对我与CSS的Lottie动画创建的SVG元素,以给它一些Border-Radius。我对JavaScript和CSS的经验不足,我不知道该怎么做。

我已经尝试通过使用以下方式将SVG元素定位为Lottie-player-Element的孩子,因为

lottie-player svg {
border-radius: 9px;
}

我认为这是不起作用的,因为SVG在原始HTML代码中不存在,并且后来通过JavaScript添加。那是对的吗?

您有什么想法如何通过CSS赋予这个动画圆角?

这是一个可以播放的代号: https://codepen.io/kartenhouse/kartenhouse/pen/pen/pen/pen/jjjpmxem

非常感谢您的帮助!

I'm trying to target the svg-element that's created by my lottie-animation with CSS to give it some border-radius. Being rather unexperienced with JavaScript and CSS, I couldn't figure out how to do it.

I've already tried targeting the svg-element as a child of the lottie-player-element by using:

lottie-player svg {
border-radius: 9px;
}

I assume this doesn't work, because the svg isn't present in the original HTML code and only added later through JavaScript. Is that correct?

Do you have any ideas how to give this animation rounded corners, ideally through CSS?

Here's a codepen to play around with: https://codepen.io/Kartenhouse/pen/JjpmXem

Thanks a lot for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2025-02-12 15:27:45

尝试创建父div,然后在那里进行所有CSS属性,而不是将其用于Lottie Player。
就像我所做的。 codepen for参考

父母

<div id="lottie">
  <lottie-player src="https://assets5.lottiefiles.com/datafiles/zc3XRzudyWE36ZBJr7PIkkqq0PFIrIBgp4ojqShI/newAnimation.json" speed="1" loop autoplay>
  </lottie-player>
</div>

html: > CSS:将CSS添加到父级,而不是HTML。

#lottie {
  height: 300px;
  width: 300px;
  border: 2px solid red;
  border-radius: 12px;
  z-index: 12;
  background-color: #000000;
}

最终输出看起来像这样

”在此处输入图像描述”

注意:如果您需要Lottie控件,则需要编写自己的逻辑才能使玩家开始和停止动画。

Try creating a parent div and do all CSS properties there instead to lottie player.
Like what I have done. Codepen for reference

HTML : Parented the lottie player

<div id="lottie">
  <lottie-player src="https://assets5.lottiefiles.com/datafiles/zc3XRzudyWE36ZBJr7PIkkqq0PFIrIBgp4ojqShI/newAnimation.json" speed="1" loop autoplay>
  </lottie-player>
</div>

CSS : Added CSS to parent div instead of HTML.

#lottie {
  height: 300px;
  width: 300px;
  border: 2px solid red;
  border-radius: 12px;
  z-index: 12;
  background-color: #000000;
}

The final output looks like this

enter image description here

Note: If you need lottie controls then you need to write your own logic for player to start and stop animation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文