JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//unpkg.com/perspective.js/lib/perspective.js"></script>
<div id="wrap">
<section data-hover-layer="0">
</section>
<p data-hover-layer="1">Perspective.js</p>
</div>
CSS
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
font-family: monospace,sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
#wrap {
height: 200px;
width: 350px;
position: relative;
}
section {
height: 100%;
background-color: #ee0d22;
}
p {
position: absolute;
top: 50%;
transform: translate3d(0, -50%, 0);
width: 100%;
text-align: center;
color: #fff;
font-size: 36px;
text-shadow: 4px 4px 4px #bb6060;
}
JavaScript
const wrap = document.querySelector('#wrap')
const hover = new perspective.Hover(wrap, {
max: 0,
scale: 1,
perspective: 900,
layers: [{
multiple: 0.5,
reverseTranslate: true
}, {
multiple: 0.1,
reverseTranslate: true
}]
})