Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -53,7 +53,7 @@ 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) };
|
|
@@ -62,7 +62,7 @@ for (let i = 0; i < 15; i++) {
|
|
| 62 |
}
|
| 63 |
|
| 64 |
camera.position.z = 12;
|
| 65 |
-
camera.position.y = 2;
|
| 66 |
|
| 67 |
// Анимация сфер с ограничением
|
| 68 |
function animate() {
|
|
@@ -71,7 +71,6 @@ function animate() {
|
|
| 71 |
spheres.forEach(sphere => {
|
| 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;
|
|
@@ -91,8 +90,26 @@ window.addEventListener('resize', () => {
|
|
| 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', () => {
|
|
@@ -100,6 +117,7 @@ document.querySelectorAll('.add-to-cart-btn').forEach(button => {
|
|
| 100 |
const serviceName = serviceCard.getAttribute('data-service');
|
| 101 |
if (!cart.includes(serviceName)) {
|
| 102 |
cart.push(serviceName);
|
|
|
|
| 103 |
alert(`${serviceName} добавлено в корзину!`);
|
| 104 |
} else {
|
| 105 |
alert(`${serviceName} уже в корзине!`);
|
|
@@ -107,13 +125,38 @@ document.querySelectorAll('.add-to-cart-btn').forEach(button => {
|
|
| 107 |
});
|
| 108 |
});
|
| 109 |
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 116 |
} else {
|
| 117 |
alert('Пожалуйста, выберите хотя бы одну услугу!');
|
| 118 |
}
|
| 119 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
| 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) };
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
camera.position.z = 12;
|
| 65 |
+
camera.position.y = 2;
|
| 66 |
|
| 67 |
// Анимация сфер с ограничением
|
| 68 |
function animate() {
|
|
|
|
| 71 |
spheres.forEach(sphere => {
|
| 72 |
sphere.position.add(sphere.userData.velocity);
|
| 73 |
|
|
|
|
| 74 |
if (Math.abs(sphere.position.x) > 10) sphere.userData.velocity.x *= -0.9;
|
| 75 |
if (sphere.position.y > 5 || sphere.position.y < -10) sphere.userData.velocity.y *= -0.9;
|
| 76 |
if (Math.abs(sphere.position.z) > 10) sphere.userData.velocity.z *= -0.9;
|
|
|
|
| 90 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 91 |
});
|
| 92 |
|
| 93 |
+
// Корзина с Local Storage
|
| 94 |
+
let cart = JSON.parse(localStorage.getItem('cart')) || [];
|
| 95 |
+
|
| 96 |
+
function updateCart() {
|
| 97 |
+
localStorage.setItem('cart', JSON.stringify(cart));
|
| 98 |
+
const cartCount = document.getElementById('cartCount');
|
| 99 |
+
cartCount.textContent = cart.length;
|
| 100 |
+
|
| 101 |
+
const cartItems = document.getElementById('cartItems');
|
| 102 |
+
cartItems.innerHTML = '';
|
| 103 |
+
if (cart.length === 0) {
|
| 104 |
+
cartItems.innerHTML = '<li>Корзина пуста</li>';
|
| 105 |
+
} else {
|
| 106 |
+
cart.forEach(item => {
|
| 107 |
+
const li = document.createElement('li');
|
| 108 |
+
li.textContent = item;
|
| 109 |
+
cartItems.appendChild(li);
|
| 110 |
+
});
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
|
| 114 |
document.querySelectorAll('.add-to-cart-btn').forEach(button => {
|
| 115 |
button.addEventListener('click', () => {
|
|
|
|
| 117 |
const serviceName = serviceCard.getAttribute('data-service');
|
| 118 |
if (!cart.includes(serviceName)) {
|
| 119 |
cart.push(serviceName);
|
| 120 |
+
updateCart();
|
| 121 |
alert(`${serviceName} добавлено в корзину!`);
|
| 122 |
} else {
|
| 123 |
alert(`${serviceName} уже в корзине!`);
|
|
|
|
| 125 |
});
|
| 126 |
});
|
| 127 |
|
| 128 |
+
// Открытие/закрытие модального окна корзины
|
| 129 |
+
const cartIcon = document.getElementById('cartIcon');
|
| 130 |
+
const cartModal = document.getElementById('cartModal');
|
| 131 |
+
const closeModal = document.getElementById('closeModal');
|
| 132 |
+
|
| 133 |
+
cartIcon.addEventListener('click', () => {
|
| 134 |
+
cartModal.style.display = 'flex';
|
| 135 |
+
updateCart();
|
| 136 |
+
});
|
| 137 |
+
|
| 138 |
+
closeModal.addEventListener('click', () => {
|
| 139 |
+
cartModal.style.display = 'none';
|
| 140 |
+
});
|
| 141 |
+
|
| 142 |
+
// Очистка корзины
|
| 143 |
+
document.getElementById('clearCartBtn').addEventListener('click', () => {
|
| 144 |
+
cart = [];
|
| 145 |
+
updateCart();
|
| 146 |
+
alert('Корзина очищена!');
|
| 147 |
+
});
|
| 148 |
+
|
| 149 |
+
// Рассчитать стоимость
|
| 150 |
+
document.getElementById('calculateBtn').addEventListener('click', () => {
|
| 151 |
if (cart.length > 0) {
|
| 152 |
const message = `Здравствуйте! Интересуют следующие услуги: ${cart.join(', ')}. Прошу рассчитать стоимость.`;
|
| 153 |
const whatsappUrl = `https://wa.me/996500398754?text=${encodeURIComponent(message)}`;
|
| 154 |
window.open(whatsappUrl, '_blank');
|
| 155 |
+
cartModal.style.display = 'none';
|
| 156 |
} else {
|
| 157 |
alert('Пожалуйста, выберите хотя бы одну услугу!');
|
| 158 |
}
|
| 159 |
+
});
|
| 160 |
+
|
| 161 |
+
// Инициализация корзины при загрузке страницы
|
| 162 |
+
updateCart();
|