Код: Выделить всё
trymoving
body
{
margin:0;
padding:0;
}
section
{
height:100vh;
background:url(background-image.png);
overflow:hidden;
}
.sec2 {
width: 100%;
position: relative;
top: 0;
left: 0;
background:url('foreground-image.png');
}
const section = document.getElementsByTagName('section')[0];
section.addEventListener('mousemove', (e) =>{
const moveX = (e.pageX * -1 / 40);
const moveY = (e.pageY * -1 / 40);
section.style.backgroundPosition = moveX + 'px ' + moveY + 'px';
});
const section2 = document.getElementsByClassName('sec2')[0];
section2.addEventListener('mousemove', (e) =>{
const moveX = (e.pageX * -1 / 10);
const moveY = (e.pageY * -1 / 10);
section2.style.backgroundPosition = moveX + 'px ' + moveY + 'px';
});
Подробнее здесь: https://stackoverflow.com/questions/674 ... -mouseover
Мобильная версия