Finding the boundary box of an HTML element without taking into account any CSS transformations

While I know that this was once the standard functionality of getBoundingClientRect(), it appears that I'm actually in a unique situation where I require this feature!

I've created a CSS animation that shifts a div vertically using translate. But, I need to determine the final position of the div... even before the animation starts.

Is there a clever method to achieve this without knowing the specifics of the animation parameters?

Answer №1

To utilize getBoundingClientRect in your code, simply follow this example:

var element = document.getElementById("animate");
window.setInterval(function() {
  var rect = element.getBoundingClientRect();
  element.innerHTML = "left position: " + Math.floor(rect.left) + "px<br/> top position: " + Math.floor(rect.top) + "px";
}, 100);
body {
  background-color: #333;
  height: 500px;
}
#animate {
  position: absolute;
  width: 300px;
  height: 300px;
  background-color: lightblue;
  animation: moveAround 7s infinite alternate;
}
@keyframes moveAround {
  from {
    left: 0;
    top: 0;
  }
  to {
    left: calc(100% - 300px);
    top: calc(100% - 300px);
  }
}
<div id="animate">WELCOME!</div>

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

Employing jQuery to conceal sub-menus upon clicking (ensuring only one is open at any given time)

Currently, I am facing an issue with the functionality of the sub menus. Below are my requirements and the progress I have made so far: Only one sub menu should be open at a time (this is working) Clicking should toggle the sub menu (not working on the s ...

Leveraging the power of AJAX to submit forms on a webpage that are dynamically created by PHP

On my page, there are multiple forms that serve as a "like" button for each post. Next to these buttons is a div called "likes$id" where the number of likes is displayed. This allows me to easily update the like count after making an AJAX call. However, I ...

Gradually make a section disappear and delete it in WordPress

Is there a way to smoothly fade out and remove a section after clicking on it in WordPress? I tried using the code below, which worked but doesn't seem to work for WordPress. I am using the Oceanwp theme, which allows me to easily add CSS and JavaScri ...

Is there a way to access just the concealed text within an element?

Is there a way to create a JavaScript function that can specifically extract hidden text from an element? Are there any existing libraries with this capability, and if so, how efficient are they? In order for an element to be considered visible ac ...

Tips on how to direct the attention to a text box within a unique dialog, ensuring that the blinking cursor highlights the input area

Is there a way to set autofocus on a textbox when opening a custom dialog box? I've tried using the autofocus attribute for the input field, but it doesn't seem to work for me. Can anyone provide guidance on how to achieve autofocus for a textfie ...

"Displaying the y-axis in d3.js: A Step-by-Step

I am a beginner in d3.js and I'm having trouble with my y-axis not showing up in the browser. Can someone please help me find a solution? var barOffset=5; var barWidth=50; var width=700,height=700; function processData(data,key){ var objects=[]; ...

Default Data Configuration for Mongoose

Exploring the realm of node.js and the MEAN stack, I am venturing into the creation of an application. Within this application, there exists a need for default data in the database. My goal is to ensure that this data is populated automatically upon the ap ...

Convert a JavaScript array into an HTML table sorted by time

I am looking to convert an array into an HTML table sorted by time, including a rank and calculating the time loss for the first place. Here is an example of the array: let array = [ ["McNulty Oscar", "USA", "108:45.1"], ["Johansson Anton", "SWE", "87 ...

Dynamically load external files into a static popup using jQuery

I'm having trouble opening a popup along with loading an external file. Initially, the process works perfectly the first two times. However, on the third attempt, I encounter a "File not Found" error, even though the file is present. (This occurs on a ...

How to merge multiple hover effects using JS or JQuery

I am just beginning my journey as a web designer and currently delving into the world of JavaScript for enhancing website functionality. While working on my latest project, I encountered a challenge. I wanted to create a menu where specific elements would ...

There seems to be a display issue with the DataTables tables

Utilizing Bootstrap 4, I followed the example provided by DataTables on their website: link. The specific code that was implemented can be found here: link Take a look at how it appears: http://pastebin.com/HxSNUnLq Any suggestions on how to resolve th ...

Get rid of numerous div elements in a React.js application with the help of a Remove button

I need help figuring out how to efficiently remove the multiple div's that are generated using the add button. I am struggling to grasp how to pass the parent div's id into the delete method from the child div. Additionally, I'm wondering if ...

Sharing data between pages in Ionic and Angular with POST requests

Currently, I am utilizing Ionic for developing a mobile application and have decided to incorporate very basic authentication (without any security measures) into the app. The process involves validating user credentials against a database through a POST r ...

What is the process for including a task in the current method?

I've been working on building a web app similar to Google Calendar. I have successfully created the necessary objects and methods, but now I need to implement a feature that allows users to add tasks. My current idea is for users to input a task which ...

What is the best way to incorporate ngRoute into Jasmine / Karma for testing AngularJS applications?

I am currently working on setting up a basic unit test example. Everything is running smoothly with this app.js: var whapp = angular.module('whapp', []) .filter('reverse', [function(){ return function(string){ return string ...

Tips for efficiently implementing AJAX requests for multiple forms within a single webpage

Previously, I had a form where clicking submit would hide the form and display the result on a div with classname=dig. However, after adding more forms, all the forms started submitting at the same time instead of individually. How can I fix this issue in ...

Effortlessly verify checkboxes associated with the corresponding ID in the database

I am currently facing a challenge while working on a project using Codeigniter that I need help resolving. Here is the issue: In the view above, you can see multiple roles and permissions displayed. Each role has its own set of permissions stored in the ...

The impact of Jquery datatable version 1.10 on the dropdown component of Bootstrap version 5.1

On my website, I am utilizing Bootstrap v5.1 and Datatable v1.10 in my project. However, this version of Datatable is causing issues with the Bootstrap dropdown functionality. The dropdown menu is not opening as expected. Strangely, no errors are being gen ...

Every time I hover, my jQuery code keeps repeating the hover effect

I am currently facing an issue that has me stumped on finding a solution. The problem arises when I hover over the .div multiple times, the animation just doesn't stop and keeps running continuously. What I aim for is to have the .hidden element fad ...

The method of an ajax call may occasionally switch from POST to GET

When making a page with an ajax call based on user choices, I encountered an issue where even though it was specified as a POST request, it sometimes changed to a GET request. This resulted in the code in the called page failing. Upon further investigatio ...