Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -36,32 +36,40 @@ function animateCosmo() {
|
|
| 36 |
animateCosmo();
|
| 37 |
|
| 38 |
// Управление продуктом (ПК: мышь, мобильные: сенсор)
|
| 39 |
-
const
|
| 40 |
if ('ontouchstart' in window) {
|
| 41 |
let touchStartX = 0, touchStartY = 0;
|
| 42 |
-
|
| 43 |
touchStartX = e.touches[0].clientX;
|
| 44 |
touchStartY = e.touches[0].clientY;
|
| 45 |
});
|
| 46 |
-
|
| 47 |
const deltaX = (e.touches[0].clientX - touchStartX) / 8;
|
| 48 |
const deltaY = (e.touches[0].clientY - touchStartY) / 8;
|
| 49 |
-
|
| 50 |
});
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
});
|
| 54 |
} else {
|
| 55 |
-
|
| 56 |
const xAxis = (window.innerWidth / 2 - e.pageX) / 8;
|
| 57 |
const yAxis = (window.innerHeight / 2 - e.pageY) / 8;
|
| 58 |
-
|
| 59 |
});
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
});
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 65 |
});
|
| 66 |
}
|
| 67 |
|
|
|
|
| 36 |
animateCosmo();
|
| 37 |
|
| 38 |
// Управление продуктом (ПК: мышь, мобильные: сенсор)
|
| 39 |
+
const cream = document.getElementById('main-cream');
|
| 40 |
if ('ontouchstart' in window) {
|
| 41 |
let touchStartX = 0, touchStartY = 0;
|
| 42 |
+
cream.addEventListener('touchstart', (e) => {
|
| 43 |
touchStartX = e.touches[0].clientX;
|
| 44 |
touchStartY = e.touches[0].clientY;
|
| 45 |
});
|
| 46 |
+
cream.addEventListener('touchmove', (e) => {
|
| 47 |
const deltaX = (e.touches[0].clientX - touchStartX) / 8;
|
| 48 |
const deltaY = (e.touches[0].clientY - touchStartY) / 8;
|
| 49 |
+
cream.style.transform = `perspective(3000px) rotateY(${deltaX}deg) rotateX(${-deltaY}deg)`;
|
| 50 |
});
|
| 51 |
+
cream.addEventListener('touchend', () => {
|
| 52 |
+
cream.style.transform = 'perspective(3000px) rotateY(0deg) rotateX(0deg)';
|
| 53 |
+
});
|
| 54 |
+
cream.addEventListener('touchstart', () => {
|
| 55 |
+
cream.classList.add('active');
|
| 56 |
+
});
|
| 57 |
+
cream.addEventListener('touchend', () => {
|
| 58 |
+
cream.classList.remove('active');
|
| 59 |
});
|
| 60 |
} else {
|
| 61 |
+
cream.addEventListener('mousemove', (e) => {
|
| 62 |
const xAxis = (window.innerWidth / 2 - e.pageX) / 8;
|
| 63 |
const yAxis = (window.innerHeight / 2 - e.pageY) / 8;
|
| 64 |
+
cream.style.transform = `perspective(3000px) rotateY(${xAxis}deg) rotateX(${yAxis}deg)`;
|
| 65 |
});
|
| 66 |
+
cream.addEventListener('mouseenter', () => {
|
| 67 |
+
cream.style.filter = 'brightness(1.5)';
|
| 68 |
+
cream.style.transform = 'translateY(-30px) rotateZ(5deg) translateZ(50px)';
|
| 69 |
});
|
| 70 |
+
cream.addEventListener('mouseleave', () => {
|
| 71 |
+
cream.style.filter = 'brightness(1)';
|
| 72 |
+
cream.style.transform = 'translateY(0) rotateZ(0deg) translateZ(0)';
|
| 73 |
});
|
| 74 |
}
|
| 75 |
|