React中的Lottie Anim的动态变化宽度和高度
我正在使用Django构建的Web应用程序,并进行了反应,当屏幕更改尺寸时,我的问题要改变Lottie IMG的宽度和高度。 那是我的Lottie配置:
const defaultOptions = {
loop: true,
autoplay: true,
animationData: animation,
rendererSettings: {
preserveAspectRatio: "xMidYMid slice"
}
}
<div id='lottie-container'>
<Lottie
id='lottie-icon'
options={defaultOptions}
/>
</div>
那就是CSS媒体查询:
/*------|
Desktop |
-------*/
@media screen and (min-width:991px) {
/* LOTTIE */
#lottie-icon{
width: 400px;
height: 400px;
}
}
/*-----|
Mobile |
------*/
@media screen and (max-width:991px) {
/* LOTTIE */
#lottie-icon{
width: 200px;
height: 200px;
}
}
I'm working on a web app built in Django and React, I've a question about to change the width and height of my Lottie img when the screen change Its size.
That's my Lottie configuration:
const defaultOptions = {
loop: true,
autoplay: true,
animationData: animation,
rendererSettings: {
preserveAspectRatio: "xMidYMid slice"
}
}
<div id='lottie-container'>
<Lottie
id='lottie-icon'
options={defaultOptions}
/>
</div>
That's CSS media query:
/*------|
Desktop |
-------*/
@media screen and (min-width:991px) {
/* LOTTIE */
#lottie-icon{
width: 400px;
height: 400px;
}
}
/*-----|
Mobile |
------*/
@media screen and (max-width:991px) {
/* LOTTIE */
#lottie-icon{
width: 200px;
height: 200px;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的问题似乎是您为Lottie组件分配ID的方式。
这是您可以将类/ID分配给生成的SVG元素的方法(根据此):
然后,您可以使用媒体查询或使用大众 / VH来操纵CSS中的大小。
您将需要添加
!重要的
标签,尽管为了覆盖SVG的样式属性:Your issue here seems to be the way you assign an id to your Lottie component.
Here is how you can assign a class / id to your generated svg element (according to this):
Then you can manipulate its size in your CSS, either by using media queries or using vw / vh.
You will need to add
!important
tags though in order to override the style properties of the svg:尝试将
仅添加到您的媒体查询:
Try to add
only
to your media query:您也可以尝试使用大众和VH或百分比而不是PX。我通常倾向于将它们用于响应能力。
you can also try to use vw and vh or percentage instead of px. I usually tend to use them for responsiveness.
只需将高度和宽度提供给
lottie-container
lottie图标将占据容器的高度和宽度即可。Just give height and width to the
lottie-container
the lottie icon will take the height and width of the container.