js拖动滚动条模仿日出东方效果代码
代码语言:html
所属分类:动画
代码描述:js拖动滚动条模仿日出东方效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html lang="en"><head> <meta charset="UTF-8"> <style> html { background-color: #000700; color: #fff; font-family: sans-serif; display: flex; min-height: 100%; } body { min-width: 100%; min-height: 100%; margin: 0; } canvas.sunrise { box-shadow: 0px 0px 25px 5px rgba(0, 0, 0, 0.35); } .container { position: absolute; top: 0; right: 0; bottom: 0; left: 0; margin: auto; width: 800px; height: 800px; display: flex; flex-direction: column; justify-content: center; } input[type="range"]::-moz-range-track { background-color: blue; } canvas.backdrop { position: absolute; width: 100vw; height: 100vh; filter: blur(100px); opacity: 0.5; } </style> </head> <body > <canvas width="800" height="600" class="backdrop"></canvas> <div class="container"> <canvas class="sunrise" width="800" height="600"></canvas> <input type="range" min="0" max="9500" step="1" id="range" value="0"> <div> <label>glow enabled <input type="checkbox" checked="" id="glow_enabled"> </label> <label>filter enabled <input type="checkbox" checked="" id="filter_enabled"> </label> </div> </div> <script > const { PI, random, min } = Math; const canvas = document.querySelector("canvas.sunrise"); const ctx = canvas.getContext("2d"); const ctxBackdrop = document.querySelector("canvas.backdrop").getContext("2d"); const { width, height } = canvas.getBoundingClientRect(); const center = { x: width / 2, y: height / 2 }; let currentFrame = 0; let glow_enabled = true; let filter_enabled = true; const inputs = document. querySelectorAll("input[type='checkbox']"). forEach(input => { input.addEventListener("change", e => { switch (e.target.id) { case "glow_enabled": glow_enabled = e.target.checked; draw(currentFrame); break; case "filter_enabled": filter_enabled = e.target.checked; draw(currentFrame); break;} }); }); document.querySelector("input[type='range']").addEventListener("input", e => { requestAnimationFrame(() => { currentFrame = e.target.value; draw(currentFrame); }); }); function createRandom() { var numbers = []; return function r(i) { if (numbers.length >= i) { return numbers[i]; } else { let n = random(); numbers.push(n); return n; } }; } const random2 = createRandom(); function drawStars(ctx) { ctx.fillStyle = "white"; for (let i = 0; i < 1000; i++) { ctx.globalAlpha = random2(i) * 0.5; ctx.fillRect( random2(i + 1) * width, random2(i + 2) * height, random2(i + 3) * 2, random2(i + 4) * 2); } return ctx; } function drawSky(color) { return ctx => { ctx.fillStyle = color; ctx.fillRect(0, 0, width, height); return ctx; }; } function drawForeground(color) { return ctx => { ctx.fillStyle = color; ctx.fillRect(0, center.y + 100, width, height); return ctx; }; } function drawCircle(x, y, radius, ctx) { return ctx => { ctx.fillStyle = "white"; ctx.beginPath(); ctx.arc(x, y, .........完整代码请登录后点击上方下载按钮下载查看
网友评论0