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