Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { margin: 0; padding: 0; background: #172442; } body:before { content: ''; position: absolute; z-index: 1; background: -webkit-gradient(linear, left bottom, left top, from(#191842), color-stop(95%, transparent)); background: linear-gradient(0deg, #191842, transparent 95%); top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); width: 320px; height: 400px; box-shadow: -5px 35px 30px -20px rgba(0, 0, 0, 0.5); } body:after { position: absolute; z-index: 2; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); letter-spacing: 1.4em; margin: 0 0 0 0.6em; text-transform: uppercase; content: 'BREATHE'; color: violet; mix-blend-mode: lighten; font-size: 12px; font-family: serif; opacity: .8; } canvas { position: relative; z-index: 2; background: transparent; }
JavaScript
/*-------------------- Utils --------------------*/ const mapRange = (a, b, c, d, e) => { return (a - b) * (e - d) / (c - b) + d } const lerp = (v0, v1, t) => { return v0 * (1 - t) + v1 * t } const random = (min, max) => min + Math.random() * (max - min) const sin = (t) => (Math.sin(t)) const cos = (t) => (Math.cos(t)) const PI = Math.PI const TAO = PI * 2 const LOOP = 4 /*-------------------- Raf --------------------*/ class Raf { constructor() { this.raf() } raf() { if (this.onRaf) { window.requestAnimationFrame(() => { const o = {} o.time = window.performance.now() / 1000 o.playhead = o.time % LOOP / LOOP this.raf() this.onRaf(o) }) } } } /*-------------------- Canvas --------------------*/ class Canvas extends Raf { constructor(obj) { super() this.canvas = document.getElementById(obj.id) this.ctx = this.canvas.getContext('2d') this.resize() this.events() } resize() { this.dpr = window.devicePixelRatio this.canvas.style.width = `${window.innerWidth}px` this.canvas.style.height = `${window.innerHeight}px` this.canvas.width = window.innerWidth * this.dpr this.canvas.height = window.innerHeight * this.dpr } events() { window.addEventListener('resize', this.resize) } clear() { this.ctx.clearRect(0, 0, window.innerWidth * this.dpr, window.innerHeight * this.dpr) } onRaf() { this.clear() } } /*-------------------- Circle --------------------*/ class Circle extends Raf { constructor(obj) { super() Object.assign(this, obj) this.draw() } draw(playhead, time) { const breathe = sin(playhead * TAO) this.ctx.globalCompositeOperation = "screen" this.ctx.save() this.ctx.translate(window.innerWidth / 2 * this.dpr, window.innerHeight / 2 * this.dpr - 30 * this.dpr) this.ctx.rotate(PI) this.ctx.strokeStyle = this.color this.ctx.fillStyle = 'rgba(0, 100, 0, 0)' this.ctx.lineWidth = this.lineWidth this.ctx.beginPath() // this.radius *= 1 + Math.sin(Math.PI * 2 * playhead) * .5 for (let i = 0; i <= this.points; i++) { const p = i / this.points const times = 7 const phase = mapRange(cos(p * TAO), -1, 1, 1, mapRange(sin(((this.offset + time * this.speed) * .2 + p) * times * TAO), -1, 1, .5, .58)) let x = phase * this.radius * sin(p * TAO) let y = phase * this.radius * cos(p * TAO) const type = i === 0 ? 'moveTo' : 'lineTo' this.ctx[type](x, y) } this.ctx.fill() this.ctx.stroke() this.ctx.beginPath() this.ctx.fillStyle = this.color this.ctx.fill() this.ctx.restore() } onRaf({playhead, time}) { this.draw(playhead, time) } } /*-------------------- Init --------------------*/ const canvas = new Canvas({ id: 'canvas' }) for (let i = 0; i < 8; i++) { new Circle({ ctx: canvas.ctx, dpr: canvas.dpr, lineWidth: 1 * canvas.dpr, points: 200, offset: i * 1.5, speed: .7, radius: (150 - i * 4) * canvas.dpr, color: `hsl(${220 + i * 10}, 60%, 70%)` }) }
粒子
时间
文字
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号