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 script = document.currentScript;
|
||||||
const targetId =
|
const targetId = script?.getAttribute("data-target-id");
|
||||||
scriptElement && scriptElement.getAttribute("data-target-id")
|
|
||||||
? scriptElement.getAttribute("data-target-id")
|
|
||||||
: (console.error("data-target-id is null"), null);
|
|
||||||
|
|
||||||
window.addEventListener("scroll", () => {
|
window.addEventListener("scroll", () => {
|
||||||
const scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
const scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
||||||
const backgroundBlur = document.getElementById(targetId);
|
const backgroundBlur = document.getElementById(targetId);
|
||||||
backgroundBlur.style.opacity = scroll / 300;
|
backgroundBlur.style.opacity = scroll / 300;
|
||||||
});
|
});
|
||||||
}
|
})();
|
||||||
|
|
||||||
setBackgroundBlur();
|
|
||||||
|
|||||||
Reference in New Issue
Block a user