Testlanding / scripts.js
flpolprojects's picture
Update scripts.js
556ed46 verified
// Плавная прокрутка
function scrollToContact() {
document.querySelector('#contact').scrollIntoView({ behavior: 'smooth' });
}
// Кастомный курсор (только для десктопов)
const cursor = document.querySelector('.cursor');
const follower = document.querySelector('.cursor-follower');
if (window.innerWidth > 768) {
document.addEventListener('mousemove', (e) => {
cursor.style.left = `${e.clientX}px`;
cursor.style.top = `${e.clientY}px`;
follower.style.left = `${e.clientX - 20}px`;
follower.style.top = `${e.clientY - 20}px`;
});
}
// WebGL фон
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('webgl-bg').appendChild(renderer.domElement);
const geometry = new THREE.TorusKnotGeometry(5, 1.5, 100, 16);
const material = new THREE.MeshBasicMaterial({
color: 0xff6b6b,
wireframe: true
});
const torusKnot = new THREE.Mesh(geometry, material);
scene.add(torusKnot);
camera.position.z = 15;
function animateWebGL() {
requestAnimationFrame(animateWebGL);
torusKnot.rotation.x += 0.015;
torusKnot.rotation.y += 0.015;
torusKnot.scale.setScalar(1 + Math.sin(Date.now() * 0.001) * 0.1);
renderer.render(scene, camera);
}
animateWebGL();
// Параллакс-эффект
document.addEventListener('mousemove', (e) => {
const parallaxElements = document.querySelectorAll('[data-parallax]');
parallaxElements.forEach(el => {
const speed = 0.07;
const x = (window.innerWidth - e.pageX * speed) / 100;
const y = (window.innerHeight - e.pageY * speed) / 100;
el.style.transform = `translate(${x}px, ${y}px)`;
});
});
// Анимация загрузки
document.addEventListener('DOMContentLoaded', () => {
const elements = [document.querySelector('.cta-button'), ...document.querySelectorAll('.service-card')];
elements.forEach((el, index) => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
setTimeout(() => {
el.style.transition = 'all 1s ease';
el.style.opacity = '1';
el.style.transform = 'translateY(0)';
}, 200 + index * 150);
});
});
// Отслеживание груза (демо)
function trackCargo() {
const trackNum = document.getElementById('track-input').value;
if (trackNum) {
alert(`Груз ${trackNum}: В пути (этап 2/4). Ожидаемое время прибытия: 28 февраля 2025.`);
} else {
alert('Введите номер груза!');
}
}
// Обработка формы
document.getElementById('contact-form').addEventListener('submit', (e) => {
e.preventDefault();
alert('Заявка успешно отправлена! Мы свяжемся с вами в течение 24 часов.');
});
// Vanilla Tilt для карточек
VanillaTilt.init(document.querySelectorAll('.service-card'), {
max: 25,
speed: 400,
glare: true,
'max-glare': 0.4
});
// Мобильное меню
const menuToggle = document.querySelector('.menu-toggle');
const navList = document.querySelector('.nav-list');
menuToggle.addEventListener('click', () => {
navList.classList.toggle('active');
});