@sarthak03dot/romantic-animations
Version:
Romantic animations like hearts, sparkles, trails
2 lines (1 loc) • 2.78 kB
JavaScript
(function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r.RomanticAnimations={}))})(this,function(r){"use strict";function c(n){const t=document.getElementById(n),i=document.createElement("canvas");return i.width=t.offsetWidth,i.height=t.offsetHeight,i.style.position="absolute",i.style.top=0,i.style.left=0,i.style.pointerEvents="none",t.appendChild(i),i}function f(n){const t=n.getContext("2d"),i=[];function u(){return{x:Math.random()*n.width,y:n.height+20,size:20+Math.random()*10,speed:1+Math.random()*2}}function d(e){t.fillStyle="pink",t.beginPath(),t.moveTo(e.x,e.y),t.bezierCurveTo(e.x+e.size/2,e.y-e.size,e.x+e.size,e.y+e.size/3,e.x,e.y+e.size),t.bezierCurveTo(e.x-e.size,e.y+e.size/3,e.x-e.size/2,e.y-e.size,e.x,e.y),t.fill()}function l(){t.clearRect(0,0,n.width,n.height),Math.random()<.1&&i.push(u());for(let e=0;e<i.length;e++)i[e].y-=i[e].speed,d(i[e]);requestAnimationFrame(l)}l()}function y(n){const t=n.getContext("2d"),i=[];function u(e,o){return{x:e,y:o,size:8+Math.random()*5,alpha:1,decay:.02}}function d(e){t.fillStyle=`rgba(255, 105, 180, ${e.alpha})`,t.beginPath(),t.moveTo(e.x,e.y),t.bezierCurveTo(e.x+e.size/2,e.y-e.size,e.x+e.size,e.y+e.size/3,e.x,e.y+e.size),t.bezierCurveTo(e.x-e.size,e.y+e.size/3,e.x-e.size/2,e.y-e.size,e.x,e.y),t.fill()}n.addEventListener("mousemove",e=>{const o=n.getBoundingClientRect();i.push(u(e.clientX-o.left,e.clientY-o.top))});function l(){t.clearRect(0,0,n.width,n.height);for(let e=i.length-1;e>=0;e--)d(i[e]),i[e].alpha-=i[e].decay,i[e].alpha<=0&&i.splice(e,1);requestAnimationFrame(l)}l()}function z(n){const t=n.getContext("2d"),i=[];function u(e,o){const a=Math.random()*Math.PI*2,s=2+Math.random()*3;return{x:e,y:o,size:10+Math.random()*5,vx:Math.cos(a)*s,vy:Math.sin(a)*s,alpha:1,decay:.02}}function d(e){t.fillStyle=`rgba(255, 20, 147, ${e.alpha})`,t.beginPath(),t.moveTo(e.x,e.y),t.bezierCurveTo(e.x+e.size/2,e.y-e.size,e.x+e.size,e.y+e.size/3,e.x,e.y+e.size),t.bezierCurveTo(e.x-e.size,e.y+e.size/3,e.x-e.size/2,e.y-e.size,e.x,e.y),t.fill()}n.addEventListener("click",e=>{const o=n.getBoundingClientRect(),a=[];for(let s=0;s<20;s++)a.push(u(e.clientX-o.left,e.clientY-o.top));i.push(a)});function l(){t.clearRect(0,0,n.width,n.height);for(let e=i.length-1;e>=0;e--){const o=i[e];for(let a=o.length-1;a>=0;a--){const s=o[a];s.x+=s.vx,s.y+=s.vy,s.alpha-=s.decay,d(s),s.alpha<=0&&o.splice(a,1)}o.length===0&&i.splice(e,1)}requestAnimationFrame(l)}l()}function m(n="body"){const t=c(n);f(t)}function p(n="body"){const t=c(n);y(t)}function x(n="body"){const t=c(n);z(t)}r.startFloatingHearts=m,r.startHeartBurst=x,r.startHeartTrail=p,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});