JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<h2 class="object" data-value="3">Space<br><span>Background</span></h2>
<img src="https://i.imgur.com/5yrwyPE.png" class="object" data-value="-2" alt="">
<img src="https://i.imgur.com/C688O6f.png" class="object" data-value="6" alt="">
<img src="https://i.imgur.com/zQMI9zR.png" class="object" data-value="4" alt="">
<img src="https://i.imgur.com/JSzKUzo.png" class="object" data-value="-6" alt="">
<img src="https://i.imgur.com/dxgHvQV.png" class="object" data-value="8" alt="">
<img src="https://i.imgur.com/kbNROja.png" class="object" data-value="-4" alt="">
<img src="https://i.imgur.com/2Ud0NwP.png" class="object" data-value="5" alt="">
<img src="https://i.imgur.com/c5BGOj2.png" class="object" data-value="-9" alt="">
<img src="https://i.imgur.com/Qxs8luV.png" class="object" data-value="-5" alt="">
</div>
CSS
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
font-family: "Segoe UI", sans-serif;
background: url(bg.png)no-repeat;
background-size: cover;
height: 100vh;
}
.container{
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.container img{
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
object-fit: contain;
}
.container h2{
z-index: 1;
position: relative;
color: #fff;
font-size: 90px;
text-transform: uppercase;
font-weight: 900;
letter-spacing: 32px;
line-height: 60px;
}
.container h2 span{
font-size: 48px;
font-weight: 500;
letter-spacing: 10px;
}
@media (max-width:800px){
.container h2{
font-size: 60px;
letter-spacing: 19px;
line-height: 35px;
}
.container h2 span{
font-size: 26px;
}
}
JavaScript
function movingObjects() {
document.addEventListener("mousemove", parallax);
function parallax(e){
document.querySelectorAll(".object").forEach(function(move){
var moving_value = move.getAttribute("data-value");
var x = (e.clientX * moving_value) / 250;
var y = (e.clientY * moving_value) / 250;
move.style.transform = "translateX(" + x + "px) translateY(" + y + "px)";
});
}
}
$(".container").mousedown(function () {
$(this).mousemove(function () {
movingObjects();
});
}).mouseup(function () {
$(this).unbind('mousemove');
}).mouseout(function () {
$(this).unbind('mousemove');
});