av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

js實(shí)現(xiàn)點(diǎn)擊煙花特效

瀏覽:112日期:2024-04-16 13:57:14

代碼:

<script type='text/javascript'>function clickEffect() { let balls = []; let longPressed = false; let longPress; let multiplier = 0; let width, height; let origin; let normal; let ctx; const colours = ['#F73859', '#14FFEC', '#00E0FF', '#FF99FE', '#FAF15D']; const canvas = document.createElement('canvas'); document.body.appendChild(canvas); canvas.setAttribute('style', 'width: 100%; height: 100%; top: 0; left: 0; z-index: 99999; position: fixed; pointer-events: none;'); const pointer = document.createElement('span'); pointer.classList.add('pointer'); document.body.appendChild(pointer); if (canvas.getContext && window.addEventListener) { ctx = canvas.getContext('2d'); updateSize(); window.addEventListener(’resize’, updateSize, false); loop(); window.addEventListener('mousedown', function(e) { pushBalls(randBetween(10, 20), e.clientX, e.clientY); document.body.classList.add('is-pressed'); longPress = setTimeout(function() {document.body.classList.add('is-longpress');longPressed = true; }, 500); }, false); window.addEventListener('mouseup', function(e) { clearInterval(longPress); if (longPressed == true) {document.body.classList.remove('is-longpress');pushBalls(randBetween(50 + Math.ceil(multiplier), 100 + Math.ceil(multiplier)), e.clientX, e.clientY);longPressed = false; } document.body.classList.remove('is-pressed'); }, false); window.addEventListener('mousemove', function(e) { let x = e.clientX; let y = e.clientY; pointer.style.top = y + 'px'; pointer.style.left = x + 'px'; }, false); } else { console.log('canvas or addEventListener is unsupported!'); } function updateSize() { canvas.width = window.innerWidth * 2; canvas.height = window.innerHeight * 2; canvas.style.width = window.innerWidth + ’px’; canvas.style.height = window.innerHeight + ’px’; ctx.scale(2, 2); width = (canvas.width = window.innerWidth); height = (canvas.height = window.innerHeight); origin = { x: width / 2, y: height / 2 }; normal = { x: width / 2, y: height / 2 }; } class Ball { constructor(x = origin.x, y = origin.y) { this.x = x; this.y = y; this.angle = Math.PI * 2 * Math.random(); if (longPressed == true) {this.multiplier = randBetween(14 + multiplier, 15 + multiplier); } else {this.multiplier = randBetween(6, 12); } this.vx = (this.multiplier + Math.random() * 0.5) * Math.cos(this.angle); this.vy = (this.multiplier + Math.random() * 0.5) * Math.sin(this.angle); this.r = randBetween(8, 12) + 3 * Math.random(); this.color = colours[Math.floor(Math.random() * colours.length)]; } update() { this.x += this.vx - normal.x; this.y += this.vy - normal.y; normal.x = -2 / window.innerWidth * Math.sin(this.angle); normal.y = -2 / window.innerHeight * Math.cos(this.angle); this.r -= 0.3; this.vx *= 0.9; this.vy *= 0.9; } } function pushBalls(count = 1, x = origin.x, y = origin.y) { for (let i = 0; i < count; i++) { balls.push(new Ball(x, y)); } } function randBetween(min, max) { return Math.floor(Math.random() * max) + min; } function loop() { ctx.fillStyle = 'rgba(255, 255, 255, 0)'; ctx.clearRect(0, 0, canvas.width, canvas.height); for (let i = 0; i < balls.length; i++) { let b = balls[i]; if (b.r < 0) continue; ctx.fillStyle = b.color; ctx.beginPath(); ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2, false); ctx.fill(); b.update(); } if (longPressed == true) { multiplier += 0.2; } else if (!longPressed && multiplier >= 0) { multiplier -= 0.4; } removeBall(); requestAnimationFrame(loop); } function removeBall() { for (let i = 0; i < balls.length; i++) { let b = balls[i]; if (b.x + b.r < 0 || b.x - b.r > width || b.y + b.r < 0 || b.y - b.r > height || b.r < 0) {balls.splice(i, 1); } } }}clickEffect();//調(diào)用</script>

效果:

js實(shí)現(xiàn)點(diǎn)擊煙花特效

以上就是js實(shí)現(xiàn)點(diǎn)擊煙花特效的詳細(xì)內(nèi)容,更多關(guān)于js 煙花特效的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 久久久久国产精品午夜一区 | 酒色成人网 | 亚洲视频中文 | 成人在线免费电影 | 国产成人精品一区二 | 中文字幕三区 | 在线日韩视频 | 国产一级免费视频 | 欧美综合在线观看 | 国产91丝袜在线播放 | 99热国产精品 | 欧美伊人影院 | 日韩免费 | 精品视频一区二区 | 荷兰欧美一级毛片 | 超碰网址 | 人妖一区| 国产精品高潮呻吟久久久久 | 97免费在线视频 | 日韩国产欧美视频 | 久久午夜电影 | 日本黄色的视频 | 国产午夜精品一区二区三区嫩草 | 一区二区三区视频在线免费观看 | 亚洲精品国产电影 | 国产美女在线免费观看 | 亚洲在线| 台湾佬成人网 | 久久i | 在线免费亚洲视频 | 麻豆亚洲| 欧美精品久久久久 | 黄色毛片免费 | 成人做爰9片免费看网站 | 99免费在线观看视频 | 欧美日韩国产中文字幕 | 日韩精品影院 | 亚洲精品自在在线观看 | 天天天天操 | xx性欧美肥妇精品久久久久久 | 欧美午夜剧场 |