MediaWiki:FadeIn.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
let rect = target.getBoundingClientRect(); | let rect = target.getBoundingClientRect(); | ||
screen.style.position = ' | let computedStyle = window.getComputedStyle(target); | ||
screen.style.top = | |||
screen.style.left = | screen.style.position = 'absolute'; | ||
screen.style.top = `-${parseFloat(computedStyle.paddingTop) + 1}px`; | |||
screen.style.left = `-${parseFloat(computedStyle.paddingLeft) + 1}px`; | |||
screen.style.height = `${rect.height}px`; | screen.style.height = `${rect.height}px`; | ||
screen.style.width = `${rect.width}px`; | screen.style.width = `${rect.width}px`; | ||
Line 33: | Line 35: | ||
screen.setAttribute(blurAttribute, blur); | screen.setAttribute(blurAttribute, blur); | ||
} | } | ||
}, | }, 400, screen) | ||
} | } | ||
Latest revision as of 22:08, 24 August 2025
const fadeInAttribute = "data-fadein"; const blurAttribute = "data-fadein-blur"; function createScreen(target) { if (target.tagName !== "DIV") { console.error(`Invalid target! ${target.tagName}`); return; } let screen = document.createElement(target.tagName); let rect = target.getBoundingClientRect(); let computedStyle = window.getComputedStyle(target); screen.style.position = 'absolute'; screen.style.top = `-${parseFloat(computedStyle.paddingTop) + 1}px`; screen.style.left = `-${parseFloat(computedStyle.paddingLeft) + 1}px`; screen.style.height = `${rect.height}px`; screen.style.width = `${rect.width}px`; screen.style.backgroundColor = 'rgba(255, 255, 255, 255, 0.3)'; let blur = "10"; screen.style.backdropFilter = `blur(${blur}px)`; screen.style.webkitBackdropFilter = `blur(${blur}px)`; screen.setAttribute(blurAttribute, blur); screen.style.zIndex = 1; if (target.getAttribute && target.getAttribute(fadeInAttribute) === "true") { screen._itv = setInterval((s) => { let blur = parseInt(s.getAttribute(blurAttribute)); if (blur <= 0) { clearInterval(s._itv); } else { blur = blur - 1; screen.style.backdropFilter = `blur(${blur}px)`; screen.style.webkitBackdropFilter = `blur(${blur}px)`; screen.setAttribute(blurAttribute, blur); } }, 400, screen) } target.appendChild(screen); } $(`[${fadeInAttribute}]`).each(function () { createScreen(this); });