Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
canvas { position: absolute; top: 0; left: 0; }
JavaScript
var w = c.width = window.innerWidth, h = c.height = window.innerHeight, ctx = c.getContext( '2d' ), opts = { phrases: [ "Don't die\nit's not hard", "You're the Best", "Every day,\nYou're beautiful", "Every occasion,\nYou're clever", "A world without You?\nNah", "Keep kicking ass", "You're better than them,\nwhoever they are", "You're just amazing", "You are,\ntherefore I am", "Nothing better than You \ncould have happened to the world" ], balloons: 10, baseVelY: -1, addedVelY: -1, baseVelX: -.25, addedVelX: .5, baseSize: 20, addedSize: 10, baseSizeAdder: 2, addedSizeAdder: 2, baseIncrementer: .01, addedIncrementer: .03, baseHue: -10, addedHue: 30, font: '15px Verdana' }, cycle = 0, balloons = []; ctx.font = opts.font; function Balloon(){ this.reset(); } Balloon.prototype.reset = function(){ this.size = opts.baseSize + opts.addedSize * Math.random(); this.sizeAdder = opts.baseSizeAdder + opts.addedSizeAdder * Math.random(); this.incrementer = opts.baseIncrementer + opts.addedIncrementer * Math.random(); this.tick = 0; this.x = Math.random() * w; this.y = h + this.size; this.vx = opts.baseVelX + opts.addedVelX * Math.random(); this.vy = opts.baseVelY + opts.addedVelY * Math.random(); this.color = 'hsla(hue,70%,60%,.8)'.replace( 'hue', opts.baseHue + opts.addedHue * Math.random() ); this.phrase = opts.phrases[ ++cycle % opts.phrases.length ].split( '\n' ); this.lengths = []; for( var i = 0; i < this.phrase.length; ++i ) this.lengths.push( -ctx.measureText( this.phrase[ i ] ).width / 2 ); } Balloon.prototype.step = function(){ this.tick += this.incrementer; this.x += this.vx; this.y += this.vy; var size = this.size + this.sizeAdder * Math.sin( this.tick ); ctx.lineWidth = size / 40; ctx.strokeStyle = '#eee'; ctx.beginPath(); ctx.moveTo( this.x, this.y - 2 ); ctx.lineTo( this.x, this.y + size ); ctx.stroke(); ctx.fillStyle = this.color; ctx.translate( this.x, this.y ); ctx.rotate( Math.PI / 4 ); //ctx.fillRect( -size / 2, -size / 2, size / 2, size / 2 ); ctx.beginPath(); ctx.moveTo( 0, 0 ); ctx.arc( -size / 2, -size / 2 + size / 4, size / 4, Math.PI / 2, Math.PI * 3 / 2 ); ctx.arc( -size / 2 + size / 4, -size / 2, size / 4, Math.PI, Math.PI * 2 ); ctx.lineTo( 0, 0 ); ctx.fill(); ctx.rotate( -Math.PI / 4 ); ctx.translate( -this.x, -this.y ); ctx.translate( this.x, this.y + size + 15 ); ctx.scale( size / this.size, size / this.size ); ctx.fillStyle = '#eee'; for( var i = 0; i < this.phrase.length; ++i ) ctx.fillText( this.phrase[ i ], this.lengths[ i ], i * 15 ); ctx.scale( this.size / size, this.size / size ); ctx.translate( -this.x, -( this.y + size + 15 ) ); if( this.y < -size * 3 ) this.reset(); } function anim(){ window.requestAnimationFrame( anim ); ctx.fillStyle = '#222'; ctx.fillRect( 0, 0, w, h ); if( balloons.length < opts.balloons && Math.random() < .01 ) balloons.push( new Balloon ); for( var i = 0; i < balloons.length; ++i ) balloons[ i ].step(); } anim();
粒子
时间
文字
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号