flpolprojects commited on
Commit
8bec3c1
·
verified ·
1 Parent(s): 10de068

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +12 -16
script.js CHANGED
@@ -36,36 +36,32 @@ function animateCosmo() {
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
- cream.classList.add('active');
46
  });
47
- cream.addEventListener('touchmove', (e) => {
48
  const deltaX = (e.touches[0].clientX - touchStartX) / 8;
49
  const deltaY = (e.touches[0].clientY - touchStartY) / 8;
50
- cream.style.transform = `perspective(3000px) rotateY(${deltaX}deg) rotateX(${-deltaY}deg)`;
51
  });
52
- cream.addEventListener('touchend', () => {
53
- cream.style.transform = 'perspective(3000px) rotateY(0deg) rotateX(0deg)';
54
- cream.classList.remove('active');
55
  });
56
  } else {
57
- cream.addEventListener('mousemove', (e) => {
58
  const xAxis = (window.innerWidth / 2 - e.pageX) / 8;
59
  const yAxis = (window.innerHeight / 2 - e.pageY) / 8;
60
- cream.style.transform = `perspective(3000px) rotateY(${xAxis}deg) rotateX(${yAxis}deg)`;
61
  });
62
- cream.addEventListener('mouseenter', () => {
63
- cream.style.filter = 'brightness(1.6)';
64
- cream.style.transform = 'translateY(-40px) rotateZ(10deg) translateZ(70px)';
65
  });
66
- cream.addEventListener('mouseleave', () => {
67
- cream.style.filter = 'brightness(1.3)';
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