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

Tips for designing a responsive element with a repeating border

Desired Design: Create a dotted border on top of each li-element Adjust the size of the dots and spacing between them using CSS or image/SVG manipulation Make the width of the ul responsive for varying border widths Ensure that dots are not partially dis ...

An innovative tool for discovering how different colors will complement each other

Design may not be my strong suit, but there are times when I need to add a border line or a shade of gray to a background color. Is there a tool available where I can specify background color: #343434 color: #asdfgh and visually see how it will look wit ...

initial render results in undefined data

function Story() { let { id } = useParams(); const pin = useSelector(state => state.pins.pin); const dispatch = useDispatch(); const userid = 2 useEffect(() => { dispatch(getPin(id)); }, [dispatch, id]); return ( <div classN ...

Checking data input using React and Material-UI for enhanced form validation

Currently, I am working on implementing validation for a form constructed with material-ui components. While I have managed to get it to work, the issue lies in the fact that my validation function is triggered on every state change within the input field, ...

encountering a hiccup while deploying my MERN website on Railway platform

My latest project is a Discord clone portfolio that can be found on GitHub. I have successfully deployed the frontend to Vercel at this link. While it functions correctly in Firefox, there seems to be an issue with Chrome and Edge where network requests ge ...

Troubleshooting problem with toggling menu in ReactJS using Material UI

I've been working on a feature that involves toggling the open state of a menu using both a button and menu items. However, I'm facing an issue where the menu expands when clicked but doesn't close upon a second click. class Topbar extends R ...

CSS unable to modify the color of the switch in HTML code

I've been struggling to change the color of the Switch to yellow when it's turned on. Despite my attempts, I haven't been successful in doing so. Is it even possible to achieve this color change? <Switch size="small& ...

Trouble obtaining AJAX result using onClick event

As a newbie to AJAX, I am still trying to grasp the concept. My task involves using an AJAX call to extract specified information from an XML file. Even after carefully parsing all tag elements into my JavaScript code, I encounter a problem when attempting ...

Displaying background images as list items on a web page outside of

I am facing an issue with an unordered list within a div where the list item images are floating outside the div. Does anyone have a solution for this? You can see an example of the problem on Any assistance would be greatly appreciated! ...

Scrolling with JQuery between a webpage's header and footer

I'm having trouble keeping a div at the top of my page, but I want it to stop scrolling before reaching another div. <div class="my-top"><p>This is the top</p></div> <div class="big-one"> <div class="mini1 ...

supplying various color variables to a single class

I am working on a webpage with multiple elements sharing the same CSS class. I want each element to have a unique background color, but I don't want to create a bloated CSS file. Is there a way to achieve this by adding a parameter in my HTML like cla ...

Retrieving information from a TableRow element within Material UI

In the latest version of Material UI, I am utilizing a Table component but struggling to figure out how to fetch data from a selected row. The Table component's documentation mentions an onRowSelection prop that provides only the RowNumber of the sel ...

What is the process for modifying a Date type value in JavaScript?

I'm looking to create a graph that illustrates the sun's altitude throughout the day, resembling a sine curve. Users should be able to input a location (latitude & longitude) and a date, and the graph will adjust accordingly. I've incorpora ...

Utilize jQuery to insert a span element inside a paragraph element before it is appended to the DOM

My current task involves utilizing jQuery DOM elements to insert a few paragraphs into a div. The following code accomplishes this successfully: $('#detail_overlay').append($('<p />', { "class" : "detail_txt" }) .text( $(' ...

The server returned a response that was void of any content

I have encountered an issue while trying to retrieve data from my server. The request works perfectly fine when tested with Postman, returning the expected data. However, upon implementing the request in my application, I receive an empty object with prope ...

When using the Column width property in React Material UI, it may not automatically expand

I've been playing around with React Material UI Tables and I'm having trouble making the columns auto-expand without wrapping. I tried setting the 'width: auto' property in the <Table size="small" style={{ width: auto}}> ...

Issues with the menu pop-up functionality arise when utilizing the CSS class .active

When I have this code, the ".active" function doesn't work when clicked. However, if I change the div class from "top-menu-popup" to "top-menu-popup active" when opening the page, the menu is already activated. <div class="top-menu-popup"> ...

Enhance the appearance using material UI design elements

Is there a way to enhance styles in ReactJS? I tried extending the style, but it didn't work. cellItem:{ color: "black", fontWeight: "bold", [theme.breakpoints.down("xs")]: { fontSize: "0.8em" }, }, tableCellItem: { extend:"cel ...

Move the Material UI popover to the clicked icon's position

I am looking to create a popover similar to the image linked below. When the icon is clicked, I want the popover to display with the same user interface. Here is the code snippet that I have been using: {showPopOver && ( <Popover ...

The interaction between background-size: cover and background-position

I wanted to experiment with setting background-size: cover and testing out different background positions. Feel free to check out the live fiddle for a hands-on experience. HTML <div id="container"> </div> CSS #container { backgro ...