Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { background-color: #262d33; overflow: hidden; color: #566a79; line-height: 1.6; text-align: center; } a { color: inherit; font-weight: bold; } a:hover { color: #e45e5e; } a:focus { background-color: #e45e5e; outline: .25em solid #e45e5e; color: #1d3246; } canvas { display: block; max-width: 75vmin; background-color: #e45e5e; } .container { box-sizing: border-box; display: grid; height: 100vh; width: 100vw; padding: 1em; align-items: center; justify-items: center; }
JavaScript
const MathUtils = { lerp(a, b, t) { return a + t * (b - a); }, minMax(n, min = 0, max = 1) { return Math.max(min, Math.min(max, n)); } }; const Animation = { animate(callback) { const update = (time) => { if (!callback(time)) return; requestAnimationFrame(update); }; update(performance.now()); }, createTween(duration, callback) { const start = performance.now(); const end = start + duration; this.animate((now) => { callback(Math.min(1, (now - start) / duration)); return now < end; }); }, Easing: { inOut(t) { const a = MathUtils.lerp(Math.PI * -0.5, Math.PI * 0.5, t); return (Math.sin(a) + 1) * 0.5; }, }, }; const createTile = (size) => { const context = document.createElement('canvas').getContext('2d'); context.canvas.height = size; context.canvas.width = size; context.lineWidth = size * 0.125; context.strokeStyle = '#1d3246'; context.beginPath(); context.arc(0, 0, size * .5, 0, Math.PI * 2); context.stroke(); context.beginPath(); context.arc(size, size, size * .5, 0, Math.PI * 2); context.stroke(); return context.canvas; }; const createGrid = (gridSize, tile) => { const gridSizeX = gridSize + 2; const gridSizeY = gridSize; const context = document.createElement('canvas').getContext('2d'); context.canvas.height = gridSize * tile.height; context.canvas.width = gridSize * tile.width; return { canvas: context.canvas, context: context, size: gridSize, sizeX: gridSizeX, tiles: new Array(gridSizeX * gridSizeY).fill().map((_, index) => { const x = index % gridSizeX - 1; const y = Math.floor(index / gridSizeX); const turn = x + y; return { turn, x, y }; }), getX(gridX) { return gridX * tile.width; }, getY(gridY) { return gridY * tile.height; }, render() { this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); this.tiles.forEach((tileData) => { const angle = tileData.turn * Math.PI * 0.5; const x = this.getX(tileData.x); const y = this.getY(tileData.y); const tileWidthHalf = 0.5 * tile.width; const tileHeightHalf = 0.5 * tile.height; context.save(); context.translate(x + tileWidthHalf, y + tileHeightHalf); context.rotate(angle); context.drawImage(tile, -tileWidthHalf, -tileHeightHalf); context.restore(); }); }, }; }; const GridAnimations = { shift(grid) { const tweenData = grid.tiles.map((tileData) => { // Flooring the turn fixes when rAF doesn't trigger when page is in the background const xStart = Math.floor(tileData.x); const xEnd = xStart + (tileData.y % 2 === 0 ? - 1 : 1); return { xStart, xEnd, }; }); Animation.createTween(1000, (tLinear) => { grid.tiles.forEach((tileData, index) => { const offset = tileData.y / (grid.size - 1); const tLinearLocal = tLinear * 2 - offset; const tween = tweenData[index]; const t = Animation.Easing.inOut(MathUtils.minMax(tLinearLocal)); tileData.x = MathUtils.lerp(tween.xStart, tween.xEnd, t); tileData.x = ((tileData.x + 1 + grid.sizeX) % grid.sizeX) - 1; }); grid.render(); }); }, turn(grid, cycle, frame) { const tweenData = grid.tiles.map((tileData) => { // Flooring the turn fixes when rAF doesn't trigger when page is in the background const turnStart = Math.floor(tileData.turn); const turnEnd = turnStart + (tileData.x * tileData.y + Math.floor(frame / cycle)) % 3 - 1; return { turnStart, turnEnd, }; }); Animation.createTween(1000, (tLinear) => { grid.tiles.forEach((tileData, index) => { const offset = tileData.y / (grid.size - 1); const tLinearLocal = tLinear * 2 - offset; const tween = tweenData[index]; const t = Animation.Easing.inOut(MathUtils.minMax(tLinearLocal)); tileData.turn = MathUtils.lerp(tween.turnStart, tween.turnEnd, t); }); grid.render(); }); }, }; const tile = createTile(32); const grid = createGrid(32, tile); grid.render(); let frame = 0; setInterval(() => { if (frame % 2 === 1) { GridAnimations.turn(grid, 4, frame); } else { GridAnimations.shift(grid); } frame++; }, 2000); document.getElementById('container-canvas').appendChild(grid.canvas);
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>奇怪的图案-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号