This looks like an easy one imo but I am missing something as I cant get it to run.
I want to use transform with the perspective() and rotateY() functions to create a perspective for the element. Then use a transition to update the transform attribute's value on hover. And change the rotateY() value to negative to mirror the perspective effect from left to right.
The Codepen is here working and I am creating it in React .
My App.tsx that is not working
I declared all styles and apply them inline.
import React from 'react';
import { Box } from '@mui/material';
const styles = {
imageCard: {
display: ' inline-block',
boxSizing: 'border-box',
margin: '1rem',
width: '240px',
height: '320px',
padding: '8px',
borderRadius: '1rem',
background: 'url(https://picsum.photos/id/1049/240/320)',
boxShadow: 'rgba(0, 0, 0, 0.25) 0px 25px 50px -12px',
},
perspectiveLeft: {
transform: 'perspective(1500px) rotateY(15deg)',
transition: 'transform 1s ease 0s',
},
'perspectiveLeft:hover': {
transform: 'perspective(3000px) rotateY(5deg)',
},
perspectiveRight: {
transform: 'perspective(1500px) rotateY(-15deg)',
transition: 'transform 1s ease 0s',
},
'perspectiveRight:hover': {
transform: 'perspective(3000px) rotateY(-5deg)',
},
};
function Perspective() {
return (
<Box styles={styles.imageCard}>
<Box style={styles.perspectiveLeft}></Box>
<Box style={styles.perspectiveRight}></Box>
</Box>
);
}
export { Perspective };