Refactor createEid function to enhance lantern and star generation logic [skip ci]
This commit is contained in:
@@ -38,35 +38,44 @@ observer.observe(document.body, {
|
|||||||
|
|
||||||
|
|
||||||
function createEid(container) {
|
function createEid(container) {
|
||||||
for (let i = 0; i < 25; i++) {
|
const starCount = 20;
|
||||||
|
const lanternCount = Math.floor(Math.random() * 3) + 4; // 4 to 6 lanterns
|
||||||
|
|
||||||
|
// Create evenly spaced lanterns
|
||||||
|
const segmentWidth = 100 / lanternCount;
|
||||||
|
for (let i = 0; i < lanternCount; i++) {
|
||||||
const symbol = document.createElement('div');
|
const symbol = document.createElement('div');
|
||||||
symbol.className = 'eid-symbol';
|
symbol.className = 'eid-symbol lantern-rope';
|
||||||
const isLantern = Math.random() > 0.8;
|
|
||||||
|
|
||||||
if (isLantern) {
|
// Base position within segment, with slight random jitter
|
||||||
symbol.classList.add('lantern-rope');
|
const baseLeft = (i * segmentWidth) + (segmentWidth * 0.2);
|
||||||
symbol.style.left = `${Math.random() * 90 + 5}%`;
|
const jitter = Math.random() * (segmentWidth * 0.6);
|
||||||
symbol.style.animationDelay = `${Math.random() * -4}s`;
|
symbol.style.left = `${baseLeft + jitter}%`;
|
||||||
const ropeLen = 15 + Math.random() * 15; // 15vh to 30vh
|
|
||||||
symbol.style.height = `${ropeLen}vh`;
|
|
||||||
|
|
||||||
const lanternSpan = document.createElement('span');
|
symbol.style.animationDelay = `${Math.random() * -4}s`;
|
||||||
lanternSpan.className = 'lantern-emoji';
|
const ropeLen = 15 + Math.random() * 15; // 15vh to 30vh
|
||||||
lanternSpan.textContent = '🏮';
|
symbol.style.height = `${ropeLen}vh`;
|
||||||
symbol.appendChild(lanternSpan);
|
|
||||||
} else {
|
const lanternSpan = document.createElement('span');
|
||||||
symbol.textContent = eidSymbols[Math.floor(Math.random() * eidSymbols.length)];
|
lanternSpan.className = 'lantern-emoji';
|
||||||
symbol.classList.add('floating-star');
|
lanternSpan.textContent = '🏮';
|
||||||
symbol.style.left = `${Math.random() * 100}%`;
|
symbol.appendChild(lanternSpan);
|
||||||
symbol.style.top = `${Math.random() * 100}%`;
|
|
||||||
symbol.style.animationDelay = `${Math.random() * -5}s`;
|
container.appendChild(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create random floating stars
|
||||||
|
for (let i = 0; i < starCount; i++) {
|
||||||
|
const symbol = document.createElement('div');
|
||||||
|
symbol.className = 'eid-symbol floating-star';
|
||||||
|
symbol.textContent = eidSymbols[Math.floor(Math.random() * eidSymbols.length)];
|
||||||
|
symbol.style.left = `${Math.random() * 100}%`;
|
||||||
|
symbol.style.top = `${Math.random() * 100}%`;
|
||||||
|
symbol.style.animationDelay = `${Math.random() * -5}s`;
|
||||||
|
|
||||||
symbol.addEventListener('animationiteration', () => {
|
symbol.addEventListener('animationiteration', () => {
|
||||||
if (!isLantern) {
|
symbol.style.left = `${Math.random() * 90 + 5}%`;
|
||||||
symbol.style.left = `${Math.random() * 90 + 5}%`;
|
symbol.style.top = `${Math.random() * 100}%`;
|
||||||
symbol.style.top = `${Math.random() * 100}%`;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
container.appendChild(symbol);
|
container.appendChild(symbol);
|
||||||
|
|||||||
Reference in New Issue
Block a user