<div class="scene">
<div class="item a"></div>
<div class="item b"></div>
<div class="item c"></div>
</div>
body {
height: 100vh;
margin: 0;
}
.scene {
position: relative;
width: 100vw;
transform-style: preserve-3d;
perspective: 4vw;
perspective-origin: 50vw 50vh;
}
.item {
position: absolute;
left: 50vw;
top: 50vh;
width: 10vh;
height: 10vh;
background: blue;
border: 1px solid #ccc;
}
.item.a {
transform: translate3d(2vw, 2vh, 1vh);
}
.item.b {
transform: translate3d(4vw, 6vh, 2vh);
}
.item.c {
transform: translate3d(8vw, -2vh, 4vh);
}
/**
* для вопроса https://qna.habr.com/q/971293
* Как называется такая анимация, и как ее делать вне конструкторов?
*/
window.addEventListener("mousemove", parallax);
const scene = document.querySelector("div.scene");
function parallax(e) {
const x = window.innerWidth - e.pageX;
const y = window.innerHeight - e.pageY;
scene.style.perspectiveOrigin = `${x}px ${y}px`;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.