亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

js實現點擊煙花特效

瀏覽:84日期: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();//調用</script>

效果:

js實現點擊煙花特效

以上就是js實現點擊煙花特效的詳細內容,更多關于js 煙花特效的資料請關注好吧啦網其它相關文章!

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 国产欧美成人免费观看视频 | 在线观看久草视频 | 国产亚洲欧美日韩综合综合二区 | 尤物在线免费视频 | 在线亚洲一区二区 | 国产精品一二三 | 国产在线精品观看一区 | 黄色小视频免费 | 久久亚洲伊人成综合人影院 | 黑人狂躁日本妞中文字幕 | 精品视频vs精品视频 | 欧美精品亚洲精品日韩经典 | 久久精品韩国日本国产 | 91视频看看| 91宅男| 欧美成人在线影院 | 亚洲福利秒拍一区二区 | 我们不能是朋友未删减版在线看 | 图片区亚洲色图 | 国产日韩精品欧美一区色 | 扒开双腿猛进入jk校视频 | 最近最新中文字幕在线第一页 | 天天摸天天碰色综合网 | 免费xxxxx大片在线观看影视 | 日本免费一级片 | 91热爆国产露脸 | 91短视频版在线观看www | a一区二区三区视频 | 国产成人盗拍精品免费视频 | 免费福利小视频 | 18黄网站 | 免费手机黄色网址 | free性欧美chinese乱子 | 成人乱码 | 欧美精品久久久亚洲 | 国产啪爱视频精品免视 | 国产精品视频第一页 | 夜鲁鲁鲁夜夜综合视频欧美 | 日本爽妇网 | 亚洲国产情侣偷自在线二页 | 自拍视频国产 |