I need assistance with resizing a lottie animation component on my website's landing page to set its display to none on mobile devices. How can I achieve this?
See the lottie component code below:
import React from "react";
import Lottie from "react-lottie";
import data from "./Lottie/87736-car-animation.json";
export default function App() {
const defaultOptions = {
loop: true,
autoplay: true,
animationData: data,
rendererSettings: {
preserveAspectRatio: "xMidYMid slice",
},
};
return (
<div id="lottie">
<Lottie
options={defaultOptions}
height={800}
width={1000}
style={{
top: "30%",
right: "10%",
zIndex: -1,
overflow: "hidden",
position: "fixed",
}}
/>
</div>
);
}
This is the home component:
import Lottie from "../Components/Lottie";
import React from "react";
function Landing () => {
let width = window.innerWidth;
if (width > 600px) {
console.log(width);
} else {
document.getElementById("lottie").style.display = "none";
}
<Lottie className="col-lg-8 col-sm-12 lottie d-none" />
}
export default Landing;
I attempted using external CSS as well:
@media screen and (max-width: 600px) {
.lottie {
display: none !important;
}
}