mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 16:31:52 +01:00
Merge pull request #2278 from servedsmart/refactor-background-blur
♻️ Refactor: Use IIFE for background-blur and simplify code
This commit is contained in:
@@ -1,15 +1,10 @@
|
||||
function setBackgroundBlur() {
|
||||
const scriptElement = document.currentScript;
|
||||
const targetId =
|
||||
scriptElement && scriptElement.getAttribute("data-target-id")
|
||||
? scriptElement.getAttribute("data-target-id")
|
||||
: (console.error("data-target-id is null"), null);
|
||||
(() => {
|
||||
const script = document.currentScript;
|
||||
const targetId = script?.getAttribute("data-target-id");
|
||||
|
||||
window.addEventListener("scroll", () => {
|
||||
const scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
||||
const backgroundBlur = document.getElementById(targetId);
|
||||
backgroundBlur.style.opacity = scroll / 300;
|
||||
});
|
||||
}
|
||||
|
||||
setBackgroundBlur();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user