<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/gsap.min.js'></script><script src="./script.js"></script>
<style>
/*Видимое разрешение (заменить 480px на своё)*/
@media screen and (min-width: 480px) {
.image_transform_1, .image_transform_2, .image_transform_3, .image_transform_4 {
top: 0 !important;
left: 0 !important;
position: fixed;
z-index: 1 !important;
}
}
</style>
<script>
// Видимое разрешение (заменить 480px на своё)
if ($(window).width() > 480) {
gsap.set(".image_transform_1", {xPercent: -50, yPercent: -50});
const image_transform_4 = document.querySelector(".image_transform_1");
const pos_4 = { x: window.innerWidth / 2, y: window.innerHeight / 2 };
const mouse_4 = { x: pos_4.x, y: pos_4.y };
// Меняем значение скорости изображения (.05)
const speed_4 = .05;
const xSet_4 = gsap.quickSetter(image_transform_4, "x", "px");
const ySet_4 = gsap.quickSetter(image_transform_4, "y", "px");
window.addEventListener("mousemove", e => {
mouse_4.x = e.x;
mouse_4.y = e.y;
});
gsap.ticker.add(() => {
const dt_4 = 1.0 - Math.pow(1.0 - speed_4, gsap.ticker.deltaRatio());
pos_4.x += (mouse_4.x - pos_4.x) * dt_4;
pos_4.y += (mouse_4.y - pos_4.y) * dt_4;
xSet_4(pos_4.x);
ySet_4(pos_4.y);
});
}
</script>