Surprising behavior of translateZ in Framer Motion

Trying to position elements in a circular layout has led to unexpected behavior when using framer motion's translateZ. By applying styles with a template literal without shorthand for transforms, the desired effect is achieved:

transform: `
  rotateY(${
    i * (360 / images.length) <= 180 ? 
    i * (360 / images.length) : 
    ((i - (images.length)) * (360 / images.length))
  }deg) 
  translateZ(300px)
` 

However, using framer motion shorthand produces a different result:

rotateY: 
  i * (360 / images.length) <= 180 ?
  i * (360 / images.length) : 
  ((i - (images.length)) * (360 / images.length)),
translateZ: '300px',

In addition, applying only a rotateY using framer motion shorthand automatically includes a translateZ(0px). Attempting to set a custom translateZ will render both styles inline:

translateZ(300px) rotateY(-45deg) translateZ(0px);

Explore this Codesandbox link. You can experiment by commenting out one of the transform style blocks to observe the differing outcomes.

Answer №1

To achieve the desired effect, it is important to set translateZ as the z property, as demonstrated in this revised version of your code. In this example, the translateZ transform is applied correctly only once.

Check out the revised code here

For your effect to work properly, rotation must be applied before the transformation, as the order of definitions matters in the transform property.

Learn more about the importance of transform order

This issue may be related to Framer Motion, as they have specified a particular order for transformations:

Refer to the specified order by Framer Motion

You can still utilize Framer Motion properties but try to replicate the same effect while adhering to their specified transform order.

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

Attempting to show different fields depending on the chosen option

Having an issue with the signup process for my team and competition setup. I want to implement a feature where, if the user selects 'Competition', the promo code field will be displayed. However, this field should only appear when 'Competiti ...

Generate a revised object from a function and return it to the caller

What is the most efficient way to update and return a new object from a function? I came up with this function: export const addItemToCart = (currentCart, item) => { const { name, ...otherProps } = item; // if the item is already in the cart if ...

Steps for launching a hyperlink in a browser on Vue Native

I'm having trouble finding information on how to properly use the Linking component in react-native. The resources available are limited, and I'm not sure if I am implementing it correctly... Below is what I have in my template: <nb-button :o ...

What is the reason for not modifying the filtered and sorted data?

I am currently working on implementing filter options for an item list, but I am facing an issue where the filtering does not work when selecting dropdown options. Array in App.jsx const cameraShowList=[ {id:1,model:"Canon",title:"Canon ...

What could be causing the issue with my dynamic sitemap.xml file not functioning properly?

I have encountered an issue with creating a dynamic sitemap in my Next.js app. Despite following the instructions in the Next.js documentation and placing a sitemap.js file inside my app directory, I am seeing a 404 error when trying to access http://local ...

Mastering the art of employing various dialog boxes and displaying modals within ReactJS

I am struggling to understand how to implement Material UI's dialog box to display modals, close them by clicking a button, and also show different modals when clicking on various elements. Below is the code for the dialog component that I copied fro ...

How can I stop and hover over time in AngularJs Interval?

Within my UI, I have a time element that is continuously updated using AngularJS Interval. Even the milliseconds are constantly running. Is it possible to implement a feature where the time pauses when hovering over it? Any assistance would be greatly appr ...

Attempting to Retrieve Information from a Get Request using Axios

I am attempting to retrieve SQL data from a GET request using axios. My backend is set up with an express server, and the front end is built with React. In my React component, I have a function that contains the axios GET call, which I then invoke within t ...

Unable to automatically load React project after running npm start

Recently, I've encountered an issue with my local copy of a React project. Even though the project still loads successfully with npm start, I now have to manually type in localhost:/8080 in order to access it. Previously, the webpage would automatica ...

Top method to create a timer in React/Redux for automatically refreshing authentication tokens

I am implementing an access refresh jwt authentication flow and need the client to automatically send a refresh token after 10 minutes of receiving the access token. I also want to ensure that if the user's device is idle for an hour, a new access tok ...

Unable to modify the default content in a textbox using React Native

Currently, I am facing a challenge while passing parameters from one page to another using React Native navigation. The issue arises when the value passed is displayed in a textbox as it becomes uneditable. Upon pressing any key, the existing value gets de ...

Issue with React component not displaying in the browser.Here are some

I am currently following a React tutorial on and I'm facing an issue where the Counter component is not displaying on the page. The generated HTML looks like this: <html> <head> <script src="/bundle.js" ></script> </he ...

Steps to forward a restricted user to a specific webpage

I am currently utilizing NextJs and am in the process of creating a redirecting function for users who have been banned or blocked from accessing the DB/session. My attempt at this involved: redirect.js, where I created a custom redirect function. impo ...

Issue with Promise.all not waiting for Promise to resolve

After making a request to the server, I receive the data as a promise, which contains the correct information. However, for some reason, the program fails to execute properly. Prior to uploading it on Zeit, this program was functioning correctly. Fetch R ...

Where to position a button in the middle of a div that varies in size

I'm currently working with this code snippet: <div class="outer"> <ul class="list"> <li class="inner"> <div class="line">information1</div> <div class="line">hyperlink1</div&g ...

React - the function executed within a loop is only invoked once

I have implemented a click handler in my book component to facilitate page flipping. This handler appends the necessary classnames to the pages, enabling me to set up the CSS for the page flip animation. // ---------- Handle the click event on the book p ...

What is the process of integrating hegel.js with a React application created using create-react-app?

Have you heard of Hegel.js? It's a powerful type checker that I recently discovered. Surprisingly, there isn't much information online about using hegel.js with React. Check it out at ...

Position DIVs next to each other

After scouring through countless Stack Overflow threads in search of a solution to my issue, I still can't seem to get it right. Everyone suggests using float: left, float:right, overflow: hidden, display: block, etc., but none of them are working for ...

I'm having trouble managing state properly in Safari because of issues with the useState hook

Encountering Safari compatibility issues when updating a component's state. Though aware of Safari's stricter mode compared to Chrome, the bug persists. The problem arises with the inputs: Whenever an option is selected from the dropdown, it cl ...

Creating an image rollover effect when hovering between two images

I am currently working with React and trying to change 2 images by hovering over them. Here is what I have accomplished so far: Card.js <div className="image-wrapper"> <img src={sprites.front_default} className="image" a ...