Update sakura.js

pull/111/head
Who? 2025-03-03 10:33:02 +07:00 committed by GitHub
parent 1d46cd5414
commit 850dfde53a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 115 additions and 117 deletions

View File

@ -1,13 +1,11 @@
// https://raw.githubusercontent.com/jhammann/sakura/master/src/sakura.js
const Sakura = function(t, e) {
const Sakura = function (t, e) {
if (void 0 === t) throw new Error("No selector present. Define an element.");
this.el = document.querySelector(t);
var i, n;
function a(t) {
return t[Math.floor(Math.random() * t.length)];
}
function s(t, e) {
return Math.floor(Math.random() * (e - t + 1)) + t;
}
@ -18,11 +16,13 @@ const Sakura = function(t, e) {
maxSize: 14,
minSize: 10,
delay: 300,
colors: [{
colors: [
{
gradientColorStart: "rgba(255, 183, 197, 0.9)",
gradientColorEnd: "rgba(255, 197, 208, 0.9)",
gradientColorDegree: 120,
}, ],
},
],
}),
(n = e),
Object.keys(i).forEach((t) => {
@ -31,14 +31,12 @@ const Sakura = function(t, e) {
i)),
(this.el.style.overflowX = "hidden");
const o = ["webkit", "moz", "MS", "o", ""];
function r(t, e, i) {
for (let n = 0; n < o.length; n += 1) {
let a = e;
o[n] || (a = e.toLowerCase()), t.addEventListener(o[n] + a, i, !1);
}
}
function l(t) {
const e = t.getBoundingClientRect();
return (
@ -112,7 +110,7 @@ const Sakura = function(t, e) {
window.requestAnimationFrame(this.createPetal),
);
};
(Sakura.prototype.start = function() {
(Sakura.prototype.start = function () {
if (this.el.dataset.sakuraAnimId)
throw new Error("Sakura is already running.");
this.el.setAttribute(
@ -120,7 +118,7 @@ const Sakura = function(t, e) {
window.requestAnimationFrame(this.createPetal),
);
}),
(Sakura.prototype.stop = function(t = !1) {
(Sakura.prototype.stop = function (t = !1) {
const e = this.el.dataset.sakuraAnimId;
e &&
(window.cancelAnimationFrame(e),
@ -128,6 +126,6 @@ const Sakura = function(t, e) {
t ||
setTimeout(() => {
const t = document.getElementsByClassName(this.settings.className);
for (; t.length > 0;) t[0].parentNode.removeChild(t[0]);
for (; t.length > 0; ) t[0].parentNode.removeChild(t[0]);
}, this.settings.delay + 50);
});
});