Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
COLOR SPLASH!
css
* { margin: 0; padding: 0; } body { background: #111; } canvas { margin: 0; padding: 0; box-sizing: border-box; position: absolute; background: #F1FAEE; top: 50%; left: 50%; transform: translate(-50%, -50%); } p { position: absolute; top: 30px; left: 50%; transform: translatex(-50%); color: #FFF; font-family: monospace; font-size: 2rem; }
JavaScript
let canvas = document.querySelector('canvas'); let ctx = canvas.getContext('2d'); let colors = ['#FFE74C', '#FF5964', '#35A7FF', '#FFFFFF', '#011627', '#004E64', '#00A5CF', '#9FFFCB', '#25A18E', '#E4572E','#F3A712', '#A8C686','#3D348B', '#7678ED', '#F7B801', '#F18701', '#00C9B1', '#005D6C', '#00043C', '#AAAAAA', '#BBBBBB', '#FFEBB7', '#BFF4ED', '#280F34', '#B30753'] let width = canvas.width = (window.innerWidth / 2) + 100; let height = canvas.height = (window.innerHeight / 2) + 50; // CANVAS SETTINGS let cRect = canvas.getBoundingClientRect(); let startx = 0; canvas.addEventListener('mousemove', (e) => { e.preventDefault() let mouseX = e.pageX; let mouseY = e.pageY; let posX = mouseX - cRect.left; let posY = mouseY - cRect.top; let b2 = new Ball(posX, posY, Math.random() * 5, Math.random() * 5, colors[Math.floor(Math.random() * colors.length)], Math.floor(Math.random() * 10)); balls.push(b2) }) canvas.addEventListener('touchmove', (e) => { let touchobj = e.changedTouches[0]; let distX = parseInt(touchobj.clientX) let distY = parseInt(touchobj.clientY) let posX = distX - cRect.left; let posY = distY - cRect.top; let b2 = new Ball(posX, posY, Math.random() * 5, Math.random() * 5, colors[Math.floor(Math.random() * colors.length)], Math.floor(Math.random() * 10)); balls.push(b2) }) //RESIZE window.addEventListener('resize', (e) => { canvas.width = width; canvas.height = height; }) class Ball { constructor(x, y, velX, velY, color, size) { this.x = x; this.y = y; this.velX = velX; this.velY = velY; this.color = color; this.size = size || 5; } draw() { ctx.beginPath(); ctx.fillStyle = this.color; ctx.arc(this.x, this.y, this.size, 0, 2 * Math.PI); ctx.fill(); } update() { if (this.x >= width || this.x <= 0) { this.velX = -(this.velX) } if ((this.y + this.size) >= height || this.y <= 0) { this.velY = -(this.velY) } this.x += this.velX; this.y += this.velX; } } let balls = [] for (let i = 0; i < 10; i++) { let ball = new Ball(Math.random() * width, Math.random() * height, Math.random() * 5, Math.random() * 5, colors[Math.floor(Math.random() * colors.length)], Math.floor(Math.random() * 5)) balls.push(ball); } function run() { requestAnimationFrame(run) ctx.globalAlpha = .8; ctx.fillStyle = '#FFF'; ctx.fillRect(0, 0, width, height); for (let i = 0; i < balls.length; i++) { let b = balls[i] b.update() b.draw() } } run() // COLOR THE TITLE let p = document.querySelector('#title'); let text = p.textContent; p.textContent = '' for (let i = 0; i < text.length; i++) { let t = text[i] // t.textContent = '' // t.style.color = colors[Math.floor(Math.random() * colors.length)] p.textContent += t; p.style.color = colors[Math.floor(Math.random() * colors.length)] }
粒子
时间
文字
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号