Determine the corner points of the DOM element following the application of CSS transforms such as rotateX, rotateY, and perspective

To achieve the transformative effect on elements, I utilize rotateX, rotateY, and perspective properties.

By using getBoundingClientRect(), I am able to retrieve details such as top, left, bottom, right, width, and height of an element.

Is there a method to calculate the four vertices coordinate of a (DOM element) once the image has been transformed?

Apologies for any errors in my language.

Watch the video demonstration here

Check out image demos here:

https://i.sstatic.net/D0BEk.jpg

https://i.sstatic.net/E0fuj.jpg

Answer №1

When using Element.getBoundingClientRect, keep in mind the impact of CSS/SVG transform.
Discover how the return value of getBoundingClientRect changes as the transform is modified. Check it out for yourself!

If you need to determine the screen position of a transformed element's 4 corners, simply add measurer child elements to the element. Then, adjust the style of these measurer children as outlined below:

.measurer {
  display: block;
  width: 0;
  height: 0;
  position: absolute;
}
.measurer.top {
  top: 0;
}
.measurer.bottom {
  bottom: 0;
}
.measurer.left {
  left: 0;
}
.measurer.right {
  right: 0;
}

Once this is done, you can use getBoundingClientRect on the 4 measurer elements to determine their position.

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

Ways to conceal CSS on the page when triggering a different element

I am trying to achieve the functionality of hiding the black arrow when clicking on the green arrow, all without using jQuery. Here is my fiddle: http://jsfiddle.net/t5Nf8/195/ html: <div class="arrow-down"></div> <div class="arrow-up"> ...

Chakra UI is providing an incorrect font style

I recently attempted to incorporate the M Plus Rounded 1c font into my project by following the guidance provided by Chakra UI on using custom fonts (link: https://chakra-ui.com/community/recipes/using-fonts). However, I encountered an issue where Chakra U ...

I am unable to make any changes to the CSS in the WordPress code that is already integrated

I have created a static web page to serve as my primary homepage. The page is built using HTML and CSS, with some PHP code pulled from My WordPress integrated into it. One of the functionalities I've added is to display the three most recent posts on ...

Exploring the power of CSS using :after and :nth-child selectors

.app-btn { font-size: 0px !important; } .app-btn:after { content: '+2500'; visibility: visible; font-size: 15px !important; } .app-btn:after:nth-child(1) { content: "+18000"; } .app-btn:after:nth-child(2) { content: "+14000"; } < ...

Conceal the Navigation Bar Upon the Pop Up's Appearance

I Designed a Landing Page with a Fixed Mobile Nav Bar at the Bottom. There is also a Pop-Up Form that appears when clicked. How can I make sure the Nav Bar is closed when the form pops up? This issue is blocking the Send Button. Is it possible to achiev ...

What are the steps to creating an API for a web application?

I have been tasked with creating an API for my web application that will utilize another website's authentication system. While I have a basic understanding of JavaScript, PHP, and HTML, I need guidance on how to proceed with building the API. Here i ...

Exclude objects with similar ids using a method other than JavaScript's filter()

I have a list of students who need to receive medication multiple times throughout the day. The challenge is to filter the array to track how many times each student receives the same medication. The list includes three different students and repeats the s ...

Should I keep my Mobx stores in a dedicated file or include them directly in the React component?

There are a couple of ways to define observable properties and actions in MobX. One way is to include them directly in the component like this: // App.js class App extends Component { @observable a = 'something' @action change() { this. ...

Adding a dynamic form to each row in a table: A step-by-step guide

https://i.sstatic.net/HctnU.jpg Hey there! I'm facing a challenge with dynamically generated rows in a form. I want to send only the inputs from the selected row when a checkbox is clicked. Can you help me figure this out? I tried using let rowForm ...

"Securing Your Web Application with Customized HTTP Headers

I'm currently working on setting up a POST request to a REST API (Cloudsight) with basic authorization. Here is the code I have so far: var xhr = new XMLHttpRequest(); xhr.open("POST", "http://api.cloudsightapi.com/image_requests", true); xhr.setRequ ...

How to get an empty object as a response in a NODE.JS request?

For some reason, I am attempting to send an object to my backend. Even though I can retrieve valuable information from my network's payload, my req.body consistently returns an empty object. View my issue ...

Error encountered in Browserify bundle.js: exec function is not executable

After setting up Node.js, npm, samba-client, and browserify on my system, I encountered a frustrating issue in my bundle.js file. An Uncaught TypeError related to the 'exec' function has been causing trouble, and despite my efforts, I have been u ...

Enhanced functionality in MUI TablePagination now allows users to easily select their desired page

I've implemented MUI TablePagination to enable pagination in my table. The code is performing well, offering most of the features I need: Users can choose between displaying 5, 10, or 20 entries per page using a dropdown. The number of pages displaye ...

Uploading video files using XMLHttpRequest encountered an error on a particular Android device

One of our testers encountered an issue where they failed to upload a video file (.mp4) on a specific Android mobile phone. Interestingly, the same file uploaded successfully on an iPhone and another Android device. To investigate further, I attempted to ...

Resolving the issue of "Cannot GET" error with Node.js and Express

I have a class named Server in Server.js: const express = require('express'); class Server { constructor() { this.app = express(); this.app.get('/', function(req, res) { res.send('Hello World&apos ...

What is the best way to create a fixed sidebar or top bar that remains visible as I move to different pages?

Whenever I navigate to other pages, the sidebar mysteriously disappears. As I work on my project about an admin page, I'm wondering if it's necessary to include every single page? ...

Error encountered in jquery.d.ts file: Unresolved syntax issue

I am currently in the process of transitioning my jQuery project into a Typescript project. I encountered an issue when attempting to include the jQuery typings from the DefinitelyTyped Github by using the following method: ///<reference path="../../ty ...

Alternative method for handling web requests in case JavaScript is not enabled

Issue: i) I am developing a JSF2 application and need to implement a tab control on a page. When a user clicks on a tab, the content for the panel below should be loaded from an xhtml file on the server using an ajax call. ii) I want this functionality ...

What sets returning a promise from async or a regular function apart?

I have been pondering whether the async keyword is redundant when simply returning a promise for some time now. Let's take a look at this example: async function thePromise() { const v = await Inner(); return v+1; } async function wrapper() ...

Are we utilizing this JavaScript function properly for recycling it?

Two functions have been implemented successfully. One function adds the autoplay attribute to a video DOM element if the user is at a specific section on the page. The other function smoothly slides in elements with a transition effect. The only limitatio ...