Aleksmorshen commited on
Commit
b7a623b
·
verified ·
1 Parent(s): 9618a6c

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +46 -19
script.js CHANGED
@@ -30,7 +30,7 @@ window.addEventListener('scroll', () => {
30
  }
31
  });
32
 
33
- // Three.js 3D-анимация в геро-секции (плавающие сферы)
34
  const scene = new THREE.Scene();
35
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
36
  const renderer = new THREE.WebGLRenderer({ alpha: true });
@@ -38,32 +38,33 @@ renderer.setSize(window.innerWidth, window.innerHeight);
38
  document.getElementById('three-canvas').appendChild(renderer.domElement);
39
 
40
  // Свет
41
- const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
42
  scene.add(ambientLight);
43
- const pointLight = new THREE.PointLight(0xff6200, 1, 100);
44
- pointLight.position.set(10, 10, 10);
45
  scene.add(pointLight);
46
 
47
  // Создание сфер
48
  const spheres = [];
49
  const sphereGeometry = new THREE.SphereGeometry(0.5, 32, 32);
50
- const sphereMaterial = new THREE.MeshPhongMaterial({ color: 0xff6200, emissive: 0xff6200, emissiveIntensity: 0.5 });
51
 
52
- for (let i = 0; i < 20; i++) {
53
  const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
54
  sphere.position.set(
55
- (Math.random() - 0.5) * 20,
56
- (Math.random() - 0.5) * 20,
57
- (Math.random() - 0.5) * 20
58
  );
59
- sphere.userData = { velocity: new THREE.Vector3((Math.random() - 0.5) * 0.02, (Math.random() - 0.5) * 0.02, (Math.random() - 0.5) * 0.02) };
60
  scene.add(sphere);
61
  spheres.push(sphere);
62
  }
63
 
64
- camera.position.z = 15;
 
65
 
66
- // Анимация сфер
67
  function animate() {
68
  requestAnimationFrame(animate);
69
 
@@ -71,22 +72,48 @@ function animate() {
71
  sphere.position.add(sphere.userData.velocity);
72
 
73
  // Ограничение движения
74
- if (Math.abs(sphere.position.x) > 10) sphere.userData.velocity.x *= -1;
75
- if (Math.abs(sphere.position.y) > 10) sphere.userData.velocity.y *= -1;
76
- if (Math.abs(sphere.position.z) > 10) sphere.userData.velocity.z *= -1;
77
 
78
- // Легкое вращение
79
- sphere.rotation.x += 0.01;
80
- sphere.rotation.y += 0.01;
81
  });
82
 
83
  renderer.render(scene, camera);
84
  }
85
  animate();
86
 
87
- // Адаптация канваса при изменении размера окна
88
  window.addEventListener('resize', () => {
89
  camera.aspect = window.innerWidth / window.innerHeight;
90
  camera.updateProjectionMatrix();
91
  renderer.setSize(window.innerWidth, window.innerHeight);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  });
 
30
  }
31
  });
32
 
33
+ // Three.js 3D-анимация (плавающие сферы с контролем з-индекса)
34
  const scene = new THREE.Scene();
35
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
36
  const renderer = new THREE.WebGLRenderer({ alpha: true });
 
38
  document.getElementById('three-canvas').appendChild(renderer.domElement);
39
 
40
  // Свет
41
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
42
  scene.add(ambientLight);
43
+ const pointLight = new THREE.PointLight(0xff6200, 1.2, 100);
44
+ pointLight.position.set(15, 15, 15);
45
  scene.add(pointLight);
46
 
47
  // Создание сфер
48
  const spheres = [];
49
  const sphereGeometry = new THREE.SphereGeometry(0.5, 32, 32);
50
+ const sphereMaterial = new THREE.MeshPhongMaterial({ color: 0xff6200, emissive: 0xff6200, emissiveIntensity: 0.6, transparent: true, opacity: 0.8 });
51
 
52
+ for (let i = 0; i < 15; i++) {
53
  const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
54
  sphere.position.set(
55
+ (Math.random() - 0.5) * 15,
56
+ (Math.random() - 0.5) * 15 - 5, // Сдвигаем вниз, чтобы избежать текста
57
+ (Math.random() - 0.5) * 15
58
  );
59
+ sphere.userData = { velocity: new THREE.Vector3((Math.random() - 0.5) * 0.015, (Math.random() - 0.5) * 0.015, (Math.random() - 0.5) * 0.015) };
60
  scene.add(sphere);
61
  spheres.push(sphere);
62
  }
63
 
64
+ camera.position.z = 12;
65
+ camera.position.y = 2; // Сдвигаем камеру вверх для избежания пересечения
66
 
67
+ // Анимация сфер с ограничением
68
  function animate() {
69
  requestAnimationFrame(animate);
70
 
 
72
  sphere.position.add(sphere.userData.velocity);
73
 
74
  // Ограничение движения
75
+ if (Math.abs(sphere.position.x) > 10) sphere.userData.velocity.x *= -0.9;
76
+ if (sphere.position.y > 5 || sphere.position.y < -10) sphere.userData.velocity.y *= -0.9;
77
+ if (Math.abs(sphere.position.z) > 10) sphere.userData.velocity.z *= -0.9;
78
 
79
+ sphere.rotation.x += 0.02;
80
+ sphere.rotation.y += 0.02;
 
81
  });
82
 
83
  renderer.render(scene, camera);
84
  }
85
  animate();
86
 
87
+ // Адаптация канваса
88
  window.addEventListener('resize', () => {
89
  camera.aspect = window.innerWidth / window.innerHeight;
90
  camera.updateProjectionMatrix();
91
  renderer.setSize(window.innerWidth, window.innerHeight);
92
+ });
93
+
94
+ // Корзина услуг
95
+ let cart = [];
96
+
97
+ document.querySelectorAll('.add-to-cart-btn').forEach(button => {
98
+ button.addEventListener('click', () => {
99
+ const serviceCard = button.closest('.service-card');
100
+ const serviceName = serviceCard.getAttribute('data-service');
101
+ if (!cart.includes(serviceName)) {
102
+ cart.push(serviceName);
103
+ alert(`${serviceName} добавлено в корзину!`);
104
+ } else {
105
+ alert(`${serviceName} уже в корзине!`);
106
+ }
107
+ });
108
+ });
109
+
110
+ document.querySelector('.calculate-btn').addEventListener('click', () => {
111
+ if (cart.length > 0) {
112
+ const message = `Здравствуйте! Интересуют следующие услуги: ${cart.join(', ')}. Прошу рассчитать стоимость.`;
113
+ const whatsappUrl = `https://wa.me/996500398754?text=${encodeURIComponent(message)}`;
114
+ window.open(whatsappUrl, '_blank');
115
+ cart = []; // Очищаем корзину после отправки
116
+ } else {
117
+ alert('Пожалуйста, выберите хотя бы одну услугу!');
118
+ }
119
  });