Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Click
css
body { display: flex; align-items: center; justify-content: center; position: fixed; top: 0; left: 0; height: 100%; width: 100%; background-color: #131313; font-family: 'Press Start 2P', cursive; } #button { display: flex; align-items: center; justify-content: center; position: relative; top: -5px; left: -5px; overflow: hidden; width: 240px; height: 60px; padding: 0; border: 2px solid #fff; background-color: #000; box-shadow: 5px 5px 0 #fff; cursor: pointer; outline: none; -webkit-appearance: none; -moz-appearance: none; appearance: none; transition: all 0.15s ease-in-out; } #button:active { top: 0; left: 0; box-shadow: none; } #button:hover { opacity: 0.9; } span { display: block; position: relative; color: #fff; font-family: 'Press Start 2P', cursive; font-size: 18px; font-weight: bold; text-shadow: 1px 2px 0 rgba(0,0,0,0.8); z-index: 1; } canvas { display: block; position: absolute; top: 0; left: 0; }
JavaScript
const MAX_COLORS = 768; const CHUNK = 3; const GUTTER_LINES = 5; function getColors() { const setColor = (colorArray, colorIndex, r, g, b) => { const baseIndex = colorIndex << 2; colorArray[baseIndex] = r; colorArray[baseIndex + 1] = g; colorArray[baseIndex + 2] = b; colorArray[baseIndex + 3] = 0xff; }; const colors = new Uint8ClampedArray(256 * 3 * 4); for (let i = 0; i < 256; i++) { setColor(colors, i, i, 0, 0); setColor(colors, i + 256, 0xff, i, 0); setColor(colors, i + 512, 0xff, 0xff, i); } return colors; } function flipBuffers() { mainBuffer = 1 - mainBuffer; backBuffer = 1 - backBuffer; } function loop() { if (isGenerate) { for (let n = 0; n < canvas.width / CHUNK; n++) { const color = Math.random() >= 0.4 ? MAX_COLORS - 1 : 0; for (let c = 0; c < CHUNK; c++) { buffers[backBuffer][numPixels - n * CHUNK - c] = color; } } } for (let y = canvas.height - 1; y >= 1; y--) { for (let x = 1; x < canvas.width - 1; x++) { let sum = 0; const pixelIndex = y * canvas.width + x; sum += buffers[backBuffer][pixelIndex]; sum += buffers[backBuffer][pixelIndex + canvas.width - 1]; sum += buffers[backBuffer][pixelIndex + canvas.width]; sum += buffers[backBuffer][pixelIndex + canvas.width + 1]; sum /= 4; sum -= (1.0 - y / canvas.height) * 10.0; if (sum < 0) sum = 0; if (sum >= MAX_COLORS) sum = MAX_COLORS - 1; buffers[mainBuffer][pixelIndex] = sum; } } const skippedPixels = GUTTER_LINES * canvas.width; for (let i = 0; i < numPixels - skippedPixels; i++) { const baseTargetIndex = skippedPixels + i << 2; const baseSourceIndex = buffers[mainBuffer][i] << 2; fireImage.data[baseTargetIndex] = colors[baseSourceIndex]; fireImage.data[baseTargetIndex + 1] = colors[baseSourceIndex + 1]; fireImage.data[baseTargetIndex + 2] = colors[baseSourceIndex + 2]; fireImage.data[baseTargetIndex + 3] = colors[baseSourceIndex + 3]; } context.putImageData(fireImage, 0, 0); flipBuffers(); window.requestAnimationFrame(loop); } const button = document.getElementById("button"); const canvas = document.getElementById("canvas"); canvas.width = button.clientWidth; canvas.height = button.clientHeight; const colors = getColors(); const context = canvas.getContext("2d"); const fireImage = context.createImageData(canvas.width, canvas.height); const numPixels = fireImage.width * fireImage.height; const buffers = [new Uint16Array(numPixels), new Uint16Array(numPixels)]; let mainBuffer = 0; let backBuffer = 1; let isGenerate = true; button.addEventListener('click', () => { isGenerate = !isGenerate; }); window.requestAnimationFrame(loop);
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>canvas火焰按钮动画-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号