Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { background: #222; } #container { box-shadow: inset 0 1px 0 #444, 0 -1px 0 #000; height: 140px; left: 50%; margin: -70px 0 0 -60px; position: absolute; top: 50%; width: 120px; } canvas { display: block; margin: 0 auto; }
JavaScript
var waterfallCanvas = function(c, cw, ch) { var _this = this; this.c = c; this.ctx = c.getContext('2d'); this.cw = cw; this.ch = ch; this.particles = []; this.particleRate = 6; this.gravity = .15; this.init = function() { this.loop(); }; this.reset = function() { this.ctx.clearRect(0, 0, this.cw, this.ch); this.particles = []; }; this.rand = function(rMi, rMa) { return ~~((Math.random() * (rMa - rMi + 1)) + rMi); }; this.Particle = function() { var newWidth = _this.rand(1, 20); var newHeight = _this.rand(1, 45); this.x = _this.rand(10 + (newWidth / 2), _this.cw - 10 - (newWidth / 2)); this.y = -newHeight; this.vx = 0; this.vy = 0; this.width = newWidth; this.height = newHeight; this.hue = _this.rand(200, 220); this.saturation = _this.rand(30, 60); this.lightness = _this.rand(30, 60); }; this.Particle.prototype.update = function(i) { this.vx += this.vx; this.vy += _this.gravity; this.x += this.vx; this.y += this.vy; }; this.Particle.prototype.render = function() { _this.ctx.strokeStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + this.lightness + '%, .05)'; _this.ctx.beginPath(); _this.ctx.moveTo(this.x, this.y); _this.ctx.lineTo(this.x, this.y + this.height); _this.ctx.lineWidth = this.width / 2; _this.ctx.lineCap = 'round'; _this.ctx.stroke(); }; this.Particle.prototype.renderBubble = function() { _this.ctx.fillStyle = 'hsla(' + this.hue + ', 40%, 40%, 1)'; _this.ctx.fillStyle = 'hsla(' + this.hue + ', ' + this.saturation + '%, ' + this.lightness + '%, .3)'; _this.ctx.beginPath(); _this.ctx.arc(this.x + this.width / 2, _this.ch - 20 - _this.rand(0, 10), _this.rand(1, 8), 0, Math.PI * 2, false); _this.ctx.fill(); }; this.createParticles = function() { var i = this.particleRate; while (i--) { this.particles.push(new this.Particle()); } }; this.removeParticles = function() { var i = this.particleRate; while (i--) { var p = this.particles[i]; if (p.y > _this.ch - 20 - p.height) { p.renderBubble(); _this.particles.splice(i, 1); } } }; this.updateParticles = function() { var i = this.particles.length; while (i--) { var p = this.particles[i]; p.update(i); }; }; this.renderParticles = function() { var i = this.particles.length; while (i--) { var p = this.particles[i]; p.render(); }; }; this.clearCanvas = function() { this.ctx.globalCompositeOperation = 'destination-out'; this.ctx.fillStyle = 'rgba(255,255,255,.06)'; this.ctx.fillRect(0, 0, this.cw, this.ch); this.ctx.globalCompositeOperation = 'lighter'; }; this.loop = function() { var loopIt = function() { requestAnimationFrame(loopIt, _this.c); _this.clearCanvas(); _this.createParticles(); _this.updateParticles(); _this.renderParticles(); _this.removeParticles(); }; loopIt(); }; }; var isCanvasSupported = function() { var elem = document.createElement('canvas'); return !!(elem.getContext && elem.getContext('2d')); }; var setupRAF = function() { var lastTime = 0; var vendors = ['ms', 'moz', 'webkit', 'o']; for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']; }; if (!window.requestAnimationFrame) { window.requestAnimationFrame = function(callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); lastTime = currTime + timeToCall; return id; }; }; if (!window.cancelAnimationFrame) { window.cancelAnimationFrame = function(id) { clearTimeout(id); }; }; }; if (isCanvasSupported()) { var c = document.getElementById('waterfall'); var cw = c.width = 100; var ch = c.height = 140; var waterfall = new waterfallCanvas(c, cw, ch); setupRAF(); waterfall.init(); }
粒子
时间
文字
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号