Hello YU - handsome
type: channel
link: https://www.180811.xyz/index.php/tag/handsome/
items: 为你的typecho添加一个烟花点击特效

为你的typecho添加一个烟花点击特效
type: item
date: 2021-06-23T01:00:00+00:00
description: 为你的typecho添加一个烟花点击特效(适用于handsome主题)代码如下 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 { con…