mirror of
https://github.com/StarGazer114/stargazer114.github.io.git
synced 2025-01-09 23:08:16 +08:00
1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
(()=>{const e=document.getElementById("click-heart"),t=/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent);if("false"===e.getAttribute("mobile")&&t)return;const n=[],a=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||(e=>setTimeout(e,1e3/60)),o=()=>{n.forEach(((e,t)=>{if(e.alpha<=0)return document.body.removeChild(e.el),void n.splice(t,1);e.y--,e.scale+=.004,e.alpha-=.013,e.el.style.cssText=`\n left: ${e.x}px;\n top: ${e.y}px;\n opacity: ${e.alpha};\n transform: scale(${e.scale}) rotate(45deg);\n background: ${e.color};\n `})),a(o)},i=e=>{const t=document.createElement("div");t.className="heart",n.push({el:t,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:r()}),document.body.appendChild(t)},r=()=>`rgb(${~~(255*Math.random())},${~~(255*Math.random())},${~~(255*Math.random())})`;(()=>{const e=document.createElement("style");e.textContent="\n .heart {\n width: 10px;\n height: 10px;\n position: fixed;\n background: #f00;\n z-index: 99999999;\n transform: rotate(45deg);\n }\n .heart:after, .heart:before {\n content: '';\n width: inherit;\n height: inherit;\n background: inherit;\n border-radius: 50%;\n position: absolute;\n }\n .heart:after { top: -5px; }\n .heart:before { left: -5px; }\n ",document.head.appendChild(e),window.addEventListener("click",i),o()})()})(); |