canvas实现点状数字时间时钟效果代码
代码语言:html
所属分类:其他
代码描述:canvas实现点状数字时间时钟效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> html, body { height: 100vh; width: 100vw; } body, .root, .app { position: relative; } body, .root { overflow: hidden; } .root { height: 100%; width: 100%; display: grid; place-items: center; background: #101219; } .root > .app { height: 100%; width: 100%; } </style> </head> <body> <div id="root" class="root"></div> <script > "use strict"; window.addEventListener('load', onLoad); /** * It creates a canvas element and appends it to the parent element. It also returns a context and a * function that resizes the canvas to the size of the parent element * @param {HTMLElement} parent - The parent element where the canvas will be appended to. * @returns {[Context, ResizeCanvas]} The canvas context and a function that resizes the canvas to the size of the parent * element. */ function createCanvas(parent) { /** * It resizes the canvas to the size of the parent element. * @returns {Point} The canvas dimensions. */ function resizeCanvas() { const { clientHeight, clientWidth } = parent; canvas.height = clientHeight; canvas.width = clientWidth; return [clientWidth, clientHeight]; } const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); resizeCanvas(); parent.appendChild(canvas); return [ctx, resizeCanvas]; } /** * It creates a context function object that has the functions save, draw and clear. * @param {Context} ctx - Context - The context of the canvas. * @returns {ContextFunctions} `ContextFunctions` object. {@link ContextFunctions} */ function getContextFunctions(ctx) { /** * It saves .........完整代码请登录后点击上方下载按钮下载查看
网友评论0