What could be the reason behind Lottie rendering an SVG element outside of its parent div?

After struggling with this issue for an entire day, I'm seeking help to implement an animation using Lottie on my website. The animation format is 1080*1920, but the problem arises when trying to fit it within a div.

The dimensions of the div are set as:

width: auto; height: auto; or width: 100%; height: 100%;

Despite numerous attempts to adjust parameters, the exported animation always exceeds the size of the parent element, especially on smartphones. Even modifications in the JavaScript code provided by Lottie have proven unsuccessful.

You can view the animation by following this link:

animation.json

import './styles/main.scss'

const lottie = require('lottie-web')
const bodymovin = require('bodymovin')

var svgContainer = document.getElementById('homeSection');

var animData = {
    container: svgContainer,
    renderer: 'svg',
    loop: false,
    autoplay:true,
    path: 'PhoneRotate.json'
};


var anim = lottie.loadAnimation(animData);
@import "~bootstrap/scss/bootstrap";

html, body {
  background-color: #000;
  overflow: scroll;
}

.section1{
  background-color: black;
  width: 100%;
  height:100%;
}

...

</div>

https://i.sstatic.net/RAExi.png https://i.sstatic.net/2gNqH.png

Answer №1

After encountering this issue, I decided to implement a solution that prevents the element from overflowing and disrupting the overall layout:

#homeSection
{
  display: inline-block;
  position: relative;
  width: 100%;
  padding-bottom: 40%; /*Adjust according to your requirements, possibly 100%*/
  vertical-align: middle;
  overflow: hidden;
}

#homeSection > svg
{
  display: inline-block; 
  position: absolute; 
  top: 0;
  left: 0;
}

The specified ID in the code snippet corresponds to

document.getElementById('homeSection');
, which can be located within your HTML or JavaScript file responsible for generating the Lottie animation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Mastering the art of utilizing Deferred Lighting in Three.js

I am currently working on a Three.js application that requires multiple independent lights, making it ideal for a deferred lighting renderer. After researching, I found recommendations to use WebGLDeferredRenderer. However, when I tried defining a rendere ...

Could an image displayed with {display: table-cell} be a potential issue?

I am exploring the use of CSS properties display: table-* to style a list of photos. The code below is intended to demonstrate this implementation, but there seems to be an issue with the table layout in Firefox and Safari as indicated by the borders appea ...

How is the purpose of nesting functions within functions achieved in nodejs?

Take a look at this example: var tools1 = require('../tools/tools1'); var test_func = function(arg1, arg2, arg3) { var local_var_1 = "lc1"; var local_var_2 = "lc2"; return function(data) { var result = tools1.doSth(local_va ...

Discovering the maximum value and fetching it from an array

Can you help me identify the array element with the highest 'conversion' value? var barTextData = [ { term: "Roof", clicks: 11235, conversion: 3.12 }, { term: "Snow", clicks: 6309, conversion: 4.45 }, { term: "Chains" ...

What are the steps for implementing the Ionic 2 Pulling Refresher feature in my application?

Hey everyone, I'm currently working on developing a mobile app using AngularJS 2/Ionic2. I am facing an issue with implementing a pull-to-refresh feature in my app. We followed the steps outlined in this link, and while we were able to get the page to ...

Storage in private Safari mode is not synced between tabs on mobile devices

In the private mode of mobile Safari, I have successfully stored data in the localStorage. However, when I open my web app in two separate tabs, I notice that the data stored in one tab is not accessible in the other tab. This behavior may be present in ot ...

How to upload a file with JavaScript without using Ajax technology

Is it possible to upload a file using the input tag with type='file' and save it in my project folder without using ajax? Can JavaScript help me achieve this task? Below is the code snippet I am currently working on: function func3() { var ...

Tips for retrieving formatted text layout from the database

I recently encountered an issue when adding text to my MySQL database using a textarea. The format of the text, including newlines and spaces, was saved in the database but not displayed as such when viewed directly. When I retrieve this string from the da ...

Tips for positioning one set of menu buttons to the left and another set to the right

I am currently utilizing bootstrap 5 and I want to align two groups of menu buttons on the same line - one to the left and the other to the right. At the moment, my code is displaying the second group below the first group to the left. This is how it curr ...

Trigger .gif on hover using ng-repeat in AngularJS

Many solutions to this problem involve using jQuery, such as the following examples: Stop a gif animation onload, on mouseover start the activation and Animating a gif on hover. However, I'm interested in achieving the same functionality using Angular ...

Animating Sliding Images with jQuery in a Sleek Sliding Page

Just completed a 5-page sliding site, each page featuring an image slider. Utilizing an image slider within a page slider. However, when attempting to use the same image slider with different images for page slide 3, it's not functioning. Any assista ...

Utilizing Express Session with Vue CLI in a Node.js Environment

Developing a nodejs backend for my Vue application has brought up a challenge regarding user sessions and database operations. I initially tried using express-session, but the sessions appeared as undefined in subsequent requests. How can I address this is ...

What is the best way to retrieve the document DOM object within an EJS template?

I am attempting to display a list of participants when the user clicks on the button. However, every time I try, I encounter an error stating "document is not defined". (Please refrain from suggesting the use of jQuery!). <% var btn = document.getEle ...

Encountered an issue while trying to install npm package express-generator globally

Encountering an error when trying to run npm install express? Looking for the correct solution? Read on. -bash-3.2$ npm install express-generator -g npm WARN engine <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7a2bfb7b5a2 ...

Ways to retrieve the pending count of XMLHttpRequests in JavaScript

I am trying to figure out how to capture the count of pending xmlhttprequests in a web page using javascript while working with selenium and python. It seems like there is a useful link that could help me get this information, but I'm having trouble ...

What is the process for sending data to a node server using POST and receiving a responseText from it through GET?

Here is an example where I'm trying to send data from a JavaScript client to an Express Node server, validate the data against the database on the server, and respond once the verification process is complete. The data object in newHttpRequest.send(da ...

When we find ourselves within a fat arrow function

I'm struggling with this code. I have a ternary operator within a fat arrow function, but for some reason it's not working. There are no errors in browserify or the console, but the headers are not being printed. If I remove the {} and ternary o ...

Height constraint disregarded by anchor

I am facing an issue with a large textual menu where the active link space is overlapping onto the other menu items. This is causing difficulty in accurately clicking on a link. For reference, you can check out this example: http://jsfiddle.net/dhyz48j3/1 ...

The callback function is not responding properly in my HTTP POST request

I'm currently working with some code that involves callbacks: function getUserToken(data, callback) { var password_sha256 = sha256(data.password); getAppById(data.app_id).then(function(res) { console.log("app"+res); if (!r ...

Tips for triggering a postback with jquery autocomplete when an option is selected

TEST AREA I've put together a basic demo of jquery-ui autocomplete. QUERY How do I trigger a postback when a selection is made from the autocomplete list? HTML <select id="ddl"></select> <input id="field" type="text"></input& ...