Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { margin: 0; overflow: hidden; background-color: #1a59cc; }
JavaScript
const PI = Math.PI const randomInt = (min, max) => Math.floor( Math.random() * ( max - min ) + min) const fromDegToradian = deg => deg * PI / 180 const arcFromDegToradian = rad => rad * 180 / PI var canvas = document.querySelector( 'canvas') var _w, _h function refreshSize() { _w = canvas.width = innerWidth _h = canvas.height = innerHeight }; refreshSize(); var c = canvas.getContext( '2d') class Dandelion { // d: diente, p: particulas constructor( origin_x, origin_y, d_radius, p_number) { this.d_radius = d_radius | randomInt( 10, 15) this.x = this.xx = origin_x | randomInt(this.d_radius * 3, _w - this.d_radius * 3) this.y = this.yy = origin_y | _h / 2 + randomInt(0 , _h/4) this.p_number = p_number | this.d_radius * 10 this.particles = new Array( this.p_number ) this.wind = { isActive: false, force: 0.35, x: randomInt( 4, 10), y: randomInt( -10, 10) } } draw() { c.beginPath() c.arc( this.xx , this.yy, this.d_radius, 0, PI * 2, true) c.fillStyle = '#fff' c.fill() c.moveTo( this.xx, this.yy) c.quadraticCurveTo( this.x + 10, _h, this.x, this.y * 2 - 10) c.lineWidth = 3 c.strokeStyle = '#fff' c.stroke() c.closePath() } update() { this.draw() } } class Particle { constructor( x, y, size) { this.x = this.xx = x this.y = this.yy = y this.radius = randomInt( 3, 7) this.amplitude = randomInt( size * 2, size * 6) this.radians = fromDegToradian( randomInt( 0, 360 ) ) this.deg = arcFromDegToradian( this.radians ) this.wind = { isActive: false, x: Math.random() * 10 + 3, y: Math.random() * 4 - 2 } } draw() { c.beginPath() c.arc( this.x, this.y, this.radius, 0, PI * 2, true) c.strokeStyle = '#fff' c.fillStyle = 'rgba(255,255,255, 0.4)' c.fill() c.moveTo( this.x, this.y) c.lineTo( this.xx, this.yy) c.lineWidth = 0.7 c.strokeStyle = 'rgba(255,255,255, 0.7)' c.stroke() c.closePath() } pulldown() { let direction if( this.deg < 270 && this.deg > 90 ) { direction = 1 } else { direction = -1 } this.deg = direction * 0.5 + this.deg this.radians = fromDegToradian( this.deg ) } update() { if ( this.wind.isActive ) { this.pulldown() this.xx += this.wind.x this.yy += this.wind.y } this.x = this.xx + -Math.cos( this.radians ) * this.amplitude this.y = this.yy + Math.sin( this.radians ) * this.amplitude this.draw() } } // setup var lions = new Array() !function init() { for ( let i = 0; i < 7; i++) { lions.push( new Dandelion() ) } lions.forEach( l => { for( let i = 0; i < l.p_number ; i++ ) { l.particles.push( new Particle( l.xx, l.yy, l.d_radius)) } }) addEventListener( 'click', () => { lions.forEach( l => { l.particles.forEach( p => { if( Math.random() < 0.9 ) p.wind.isActive = true }) l.wind.isActive = true }) }) }(); // loop function loop() { requestAnimationFrame(loop) refreshSize() lions.forEach( l => { l.update() l.particles.forEach( p => p.update()) }) };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号