河南省网站建设_网站建设公司_Tailwind CSS_seo优化
2026/1/19 20:30:05 网站建设 项目流程

粒子动画效果

使用Canvas创建粒子动画效果,粒子会跟随鼠标移动或形成特定图案。以下代码实现了一个基础的粒子系统:

const canvas = document.getElementById('particleCanvas'); const ctx = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; const particles = []; for (let i = 0; i < 100; i++) { particles.push({ x: Math.random() * canvas.width, y: Math.random() * canvas.height, size: Math.random() * 5 + 1, speedX: Math.random() * 3 - 1.5, speedY: Math.random() * 3 - 1.5 }); } function animate() { ctx.clearRect(0, 0, canvas.width, canvas.height); particles.forEach(particle => { particle.x += particle.speedX; particle.y += particle.speedY; if (particle.x < 0 || particle.x > canvas.width) particle.speedX *= -1; if (particle.y < 0 || particle.y > canvas.height) particle.speedY *= -1; ctx.beginPath(); ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2); ctx.fillStyle = 'rgba(100, 200, 255, 0.8)'; ctx.fill(); }); requestAnimationFrame(animate); } animate();

文字渐变效果

实现文字颜色渐变和动画效果,可以通过CSS配合JS完成:

const textElement = document.getElementById('animatedText'); const colors = ['#ff3366', '#20b2aa', '#9370db', '#32cd32']; let currentIndex = 0; function changeColor() { textElement.style.color = colors[currentIndex]; currentIndex = (currentIndex + 1) % colors.length; const scale = 1 + Math.sin(Date.now() / 500) * 0.1; textElement.style.transform = `scale(${scale})`; } setInterval(changeColor, 1000);

页面滚动视差

创建具有深度感的滚动视差效果:

window.addEventListener('scroll', () => { const scrollPosition = window.pageYOffset; const parallaxElements = document.querySelectorAll('.parallax'); parallaxElements.forEach(element => { const speed = parseFloat(element.dataset.speed); const yPos = -(scrollPosition * speed); element.style.transform = `translate3d(0, ${yPos}px, 0)`; }); });

鼠标跟随光环

实现一个跟随鼠标移动的光环效果:

document.addEventListener('mousemove', (e) => { const halo = document.getElementById('mouseHalo'); halo.style.left = `${e.clientX - 50}px`; halo.style.top = `${e.clientY - 50}px`; const size = 100 + Math.sin(Date.now() / 200) * 20; halo.style.width = `${size}px`; halo.style.height = `${size}px`; halo.style.opacity = 0.7 + Math.sin(Date.now() / 300) * 0.3; });

3D卡片翻转

使用CSS 3D变换和JS实现卡片翻转效果:

const cards = document.querySelectorAll('.flip-card'); cards.forEach(card => { card.addEventListener('click', () => { card.classList.toggle('flipped'); }); });

配合CSS:

.flip-card { transition: transform 0.6s; transform-style: preserve-3d; } .flip-card.flipped { transform: rotateY(180deg); }

波浪动画效果

使用SVG和JS创建波浪动画:

const wave = document.getElementById('wave'); let offset = 0; function animateWave() { offset += 0.05; const pathData = `M0,100 Q25,130 50,100 T100,100 T150,100 T200,100 T250,100 T300,100 T350,100 T400,100 T450,100 T500,100 V200 H0 Z`; wave.setAttribute('d', pathData); requestAnimationFrame(animateWave); } animateWave();

烟花爆炸效果

Canvas实现的烟花爆炸动画:

class Firework { constructor(x, y, targetX, targetY) { this.x = x; this.y = y; this.targetX = targetX; this.targetY = targetY; this.particles = []; this.alive = true; } update() { // 更新烟花位置和粒子逻辑 } draw(ctx) { // 绘制烟花和粒子 } } const fireworks = []; document.addEventListener('click', (e) => { fireworks.push(new Firework( canvas.width/2, canvas.height, e.clientX, e.clientY )); });

背景星空效果

创建随机闪烁的星空背景:

function createStars() { const stars = []; for (let i = 0; i < 200; i++) { stars.push({ x: Math.random() * canvas.width, y: Math.random() * canvas.height, size: Math.random() * 1.5, opacity: Math.random(), speed: Math.random() * 0.05 }); } return stars; } function drawStars(ctx, stars) { stars.forEach(star => { star.opacity += (Math.random() - 0.5) * star.speed; star.opacity = Math.max(0, Math.min(1, star.opacity)); ctx.beginPath(); ctx.arc(star.x, star.y, star.size, 0, Math.PI * 2); ctx.fillStyle = `rgba(255, 255, 255, ${star.opacity})`; ctx.fill(); }); }

页面过渡动画

实现页面切换时的平滑过渡:

function pageTransition(outPage, inPage) { outPage.style.opacity = '0'; outPage.style.transform = 'translateX(-50px)'; outPage.style.transition = 'all 0.5s ease'; setTimeout(() => { outPage.style.display = 'none'; inPage.style.display = 'block'; setTimeout(() => { inPage.style.opacity = '1'; inPage.style.transform = 'translateX(0)'; }, 50); }, 500); }

编程语言C++m.renkangtang.net++c语言的魅力
编程语言C++m.pengdongny.com++c语言的魅力
编程语言C++m.sy-zjzx.com++c语言的魅力
编程语言C++m.spsrshop.com++c语言的魅力
编程语言C++m.5lue.com++c语言的魅力
编程语言C++m.ynlzz.com++c语言的魅力
编程语言C++m.hudongc.com++c语言的魅力
编程语言C++m.fmzhenxi.com++c语言的魅力
编程语言C++m.shangai.net++c语言的魅力
编程语言C++m.scw023.com++c语言的魅力

编程语言C++m.hengshuidongtong.com++c语言的魅力
编程语言C++m.meta12cLoud.com++c语言的魅力
编程语言C++m.shuangving.com++c语言的魅力
编程语言C++wab.hengshuidongtong.com++c语言的魅力
编程语言C++wab.meta12cLoud.com++c语言的魅力
编程语言C++wab.shuangving.com++c语言的魅力

编程语言C++moblie.songfudaojia.com++c语言的魅力
编程语言C++m.carandfan.com++c语言的魅力
编程语言C++wap.tlxgpsgs.com++c语言的魅力
编程语言C++blog.songfudaojia.com++c语言的魅力
编程语言C++moblie.carandfan.com++c语言的魅力
编程语言C++m.tlxgpsgs.com++c语言的魅力
编程语言C++wap.songfudaojia.com++c语言的魅力
编程语言C++blog.carandfan.com++c语言的魅力
编程语言C++moblie.tlxgpsgs.com++c语言的魅力
编程语言C++m.songfudaojia.com++c语言的魅力
编程语言C++wap.carandfan.com++c语言的魅力
编程语言C++blog.tlxgpsgs.com++c语言的魅力
编程语言C++moblie.songfudaojia.com++c语言的魅力
编程语言C++m.carandfan.com++c语言的魅力
编程语言C++wap.tlxgpsgs.com++c语言的魅力
————————————————
版权声明:本文为CSDN博主「e***9857」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/2509_94095094/article/details/157142302

打字机效果

模拟打字机逐个显示文字的效果:

function typeWriter(element, text, speed) { let i = 0; function typing() { if (i < text.length) { element.innerHTML += text.charAt(i); i++; setTimeout(typing, speed); } } typing(); } typeWriter(document.getElementById('typeText'), 'Hello, this is a typing effect!', 100);

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询