Testlend2 / script.js
flpolprojects's picture
Update script.js
879e4b1 verified
raw
history blame
3.31 kB
// Космический фон на Canvas
const canvas = document.getElementById('cosmo-canvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const particles = [];
for (let i = 0; i < 200; i++) {
particles.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
radius: Math.random() * 4 + 1,
speedX: Math.random() * 0.8 - 0.4,
speedY: Math.random() * 0.8 - 0.4,
color: `hsl(${Math.random() * 360}, 100%, 80%)`,
alpha: Math.random() * 0.5 + 0.5
});
}
function animateCosmo() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.forEach(p => {
ctx.globalAlpha = p.alpha;
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2);
ctx.fillStyle = p.color;
ctx.fill();
p.x += p.speedX;
p.y += p.speedY;
p.alpha = Math.sin(Date.now() * 0.001 + p.x) * 0.5 + 0.5;
if (p.x < 0 || p.x > canvas.width) p.speedX *= -1;
if (p.y < 0 || p.y > canvas.height) p.speedY *= -1;
});
requestAnimationFrame(animateCosmo);
}
animateCosmo();
// Управление продуктом (ПК: мышь, мобильные: сенсор)
const product = document.getElementById('cosmo-product');
if ('ontouchstart' in window) {
let touchStartX = 0, touchStartY = 0;
product.addEventListener('touchstart', (e) => {
touchStartX = e.touches[0].clientX;
touchStartY = e.touches[0].clientY;
});
product.addEventListener('touchmove', (e) => {
const deltaX = (e.touches[0].clientX - touchStartX) / 10;
const deltaY = (e.touches[0].clientY - touchStartY) / 10;
product.style.transform = `perspective(2500px) rotateY(${deltaX}deg) rotateX(${-deltaY}deg)`;
});
product.addEventListener('touchend', () => {
product.style.transform = 'perspective(2500px) rotateY(0deg) rotateX(0deg)';
});
} else {
document.addEventListener('mousemove', (e) => {
const xAxis = (window.innerWidth / 2 - e.pageX) / 10;
const yAxis = (window.innerHeight / 2 - e.pageY) / 10;
product.style.transform = `perspective(2500px) rotateY(${xAxis}deg) rotateX(${yAxis}deg)`;
});
}
// Заказ
function orderNow() {
document.body.style.transition = 'background 0.7s';
document.body.style.background = 'radial-gradient(circle, #00ffcc, #ff007a, #000)';
setTimeout(() => {
document.body.style.background = '#000';
}, 1200);
alert('Revolut запущен. Твоя кожа — космос!');
}
// Эффекты подов
function podEffect(element) {
element.style.transform = 'translateY(-30px) scale(1.2) translateZ(30px)';
element.style.boxShadow = '0 0 50px rgba(0, 255, 204, 1)';
}
function podReset(element) {
element.style.transform = 'translateY(0) scale(1) translateZ(0)';
element.style.boxShadow = 'none';
}
function podTouch(element) {
element.classList.add('active');
setTimeout(() => element.classList.remove('active'), 700);
}
// Обновление размеров Canvas при изменении окна
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});