bloodspatter-js
Version:
Blood effects library for web applications - realistic blood cells, drips, reveals, and animations
2 lines (1 loc) • 2.56 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).BloodSpatter=t()}(this,(function(){"use strict";const e={addBloodCells:function(e,t=3){for(let o=0;o<t;o++){const t=document.createElement("div"),o=Math.floor(4*Math.random())+1;t.className=`blood-cell blood-cell-${o} blood-cell-animated`;const n=e.getBoundingClientRect();t.style.left=Math.random()*(n.width-30)+"px",t.style.top=Math.random()*(n.height-30)+"px",t.style.animationDelay=2*Math.random()+"s",t.style.animationDuration=2*Math.random()+3+"s",e.appendChild(t),setTimeout((()=>{t.parentNode&&t.remove()}),6e3)}},clearBloodCells:function(e){e.querySelectorAll(".blood-cell").forEach((e=>e.remove()))},triggerBloodReveal:function(e,t){console.log("blood reveal"),e.classList.add("blood-reveal"),e.classList.add("scanning");const o=e.querySelector(".blood-reveal-text")||e.querySelector(".chat-content")||e,n=t||o.textContent;o.textContent="",o.classList.add("typing"),setTimeout((()=>{let e=0;const t=setInterval((()=>{e<n.length?(o.textContent+=n.charAt(e),e++):(clearInterval(t),o.classList.remove("typing"),o.classList.add("revealed"))}),50)}),500)},resetBloodReveal:function(e){e.classList.remove("blood-reveal","scanning");const t=e.querySelector(".blood-reveal-text")||e.querySelector(".chat-content")||e;t.classList.remove("typing","revealed");t.textContent="The victim's blood spatter pattern suggests they were standing when struck... defensive wounds on the arms indicate a struggle."},addBloodDrips:function(e,t=5){for(let o=0;o<t;o++)setTimeout((()=>{const t=document.createElement("div");t.className="blood-drip blood-drip-animated";const o=e.getBoundingClientRect();t.style.left=Math.random()*o.width+"px",t.style.top="0px",t.style.position="absolute",e.appendChild(t),setTimeout((()=>{t.parentNode&&t.remove()}),3e3)}),300*o)},addChatBloodBG:function(e){e.classList.add("chat-blood-background")},addBloodSmear:function(e){e.classList.add("blood-smear-hover")},init:function(){document.querySelectorAll(".blood-smear-hover").forEach((e=>{})),this.addBloodDrips(document.body,3),console.log("🩸 BloodSpatter.js v1.0 initialized")}};return document.addEventListener("DOMContentLoaded",(()=>{e.init()})),setInterval((()=>{e.addBloodDrips(document.body,2)}),1e4),"undefined"!=typeof module&&module.exports&&(module.exports=e),"function"==typeof define&&define.amd&&define((function(){return e})),"undefined"!=typeof window&&(window.BloodSpatter=e),e}));