canvas实现可修改参数的炫酷魔法卡片动画效果代码
代码语言:html
所属分类:动画
代码描述:canvas实现可修改参数的炫酷魔法卡片动画效果代码
代码标签: canvas 修改 参数 炫酷 魔法 卡片 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { background-color: #0a0a0a; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; overflow: hidden; } .container { position: relative; width: 100%; height: 100%; } canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .control-panel { position: fixed; top: 45px; left: 10px; background: rgba(20, 20, 30, 0.85); padding: 15px; border-radius: 12px; color: #e0e0e0; font-family: "Segoe UI", system-ui, sans-serif; z-index: 1000; backdrop-filter: blur(8px); border: 1px solid rgba(255, 255, 255, 0.1); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); max-height: 80vh; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(100, 100, 120, 0.5) transparent; } .control-panel h3 { margin: 0 0 12px 0; padding-bottom: 6px; font-size: 16px; font-weight: 600; color: #ffffff; border-bottom: 1px solid rgba(255, 255, 255, 0.1); } .control-group { margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); } .slider-control { display: flex; align-items: center; margin-bottom: 10px; } .slider-control label { width: 100px; font-size: 13px; color: #b0b0b0; } .slider-control .value-display { width: 40px; text-align: right; font-size: 13px; margin-right: 10px; color: #ffffff; } .slider-control input[type="range"] { flex-grow: 1; height: 4px; background: rgba(100, 100, 120, 0.3); border-radius: 2px; -webkit-appearance: none; outline: none; } .slider-control input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; background: #00ff88; border-radius: 50%; cursor: pointer; transition: all 0.2s; } .slider-control input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); background: #00ccff; } .control-btn { background: linear-gradient(135deg, #00ff88 0%, #00ccff 100%); border: none; color: #111; padding: 8px 16px; margin-top: 10px; border-radius: 6px; font-weight: 600; font-size: 13px; cursor: pointer; transition: all 0.2s; box-shadow: 0 2px 10px rgba(0, 255, 136, 0.3); } .control-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(0, 255, 136, 0.4); } .control-btn:active { transform: translateY(0); } .toggle-controls-btn { position: fixed; top: 10px; left: 10px; background: rgba(20, 20, 30, 0.9); color: #00ff88; border: 1px solid rgba(0, 255, 136, 0.3); padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; z-index: 1001; backdrop-filter: blur(4px); transition: all 0.2s; } .toggle-controls-btn:hover { background: rgba(0, 255, 136, 0.1); color: #ffffff; border-color: rgba(0, 255, 136, 0.6); } .control-panel::-webkit-scrollbar { width: 6px; } .control-panel::-webkit-scrollbar-track { background: transparent; } .control-panel::-webkit-scrollbar-thumb { background-color: rgba(100, 100, 120, 0.5); border-radius: 3px; } /* Add this to your existing CSS */ .slider-control input[type="range"] { transition: all 0.5s ease-out; } /* Animation for when randomizing */ @keyframes slideBounce { 0% { transform: scaleX(1); } 25% { transform: scaleX(0.95); } 50% { transform: scaleX(1.05); } 75% { transform: scaleX(0.98); } 100% { transform: scaleX(1); } } .randomizing { animation: slideBounce 0.6s ease; } .hidden { display: none; } </style> </head> <body translate="no"> <div class="container"> <canvas id="cardCanvas"></canvas> </div> <script > // Get canvas and context const canvas = document.getElementById("cardCanvas"); const ctx = canvas.getContext("2d"); // Set canvas size to match window function resizeCanvas() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; } // Call resize initially and on window resize resizeCanvas(); window.addEventListener("resize", resizeCanvas); const card = { width: 280, height: 410, cornerRadius: 15, glowColor: "#00ff88", glowIntensity: 15, glowMax: 25, rotation: 0, glowHue: 140, glowSaturation: 100, glowLightness: 50, x: 0, y: 0 }; const particleSettings = { count: 100, minSize: 1, maxSize: 4, minSpeed: 0.25, maxSpeed: 0.5, minOpacity: 0.1, maxOpacity: 0.6 }; const lineSettings = { count: 15, minWidth: 0.5, maxWidth: 2, minSpeed: 0.01, maxSpeed: 0.03, minOpacity: 0.05, maxOpacity: 0.2, waveHeight: 10, numPoints: 5 // Added numPoints to lineSettings }; const particles = []; const lines = []; const clickEffects = []; let isCardClicked = false; let clickTime = 0; let cardShakeAmount = 0; let activeHue = 140; let mouseX = 0; let mouseY = 0; let isHovering = false; let pulseTime = 0; // Pre-allocate particle objects for (let i = 0; i < particleSettings.count; i++) { particles.push({ x: 0, y: 0, size: 0, speedX: 0,.........完整代码请登录后点击上方下载按钮下载查看
网友评论0