Skip to content

Commit c397a33

Browse files
committed
♻️ Refactor: Use IIFE for background-blur and simplify code
This improves readability and removes an unnecessary function declaration by using IIFE. This is inspired by #2262 . If both are merged, this would enhance consistency
1 parent 1f49f8f commit c397a33

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

assets/js/background-blur.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
function setBackgroundBlur() {
2-
const scriptElement = document.currentScript;
3-
const targetId =
4-
scriptElement && scriptElement.getAttribute("data-target-id")
5-
? scriptElement.getAttribute("data-target-id")
6-
: (console.error("data-target-id is null"), null);
1+
(() => {
2+
const script = document.currentScript;
3+
const targetId = script?.getAttribute("data-target-id");
74

85
window.addEventListener("scroll", () => {
96
const scroll = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
107
const backgroundBlur = document.getElementById(targetId);
118
backgroundBlur.style.opacity = scroll / 300;
129
});
13-
}
14-
15-
setBackgroundBlur();
10+
})();

0 commit comments

Comments
 (0)