mirror of
				https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
				synced 2025-10-30 17:55:32 +00:00 
			
		
		
		
	JavaScript Refactor p1
This commit is contained in:
		| @@ -1,26 +1,31 @@ | ||||
| // Script for showing and acting upon the "scroll to top button" | ||||
| const scrollFunction = function () { | ||||
|     button = document.getElementById("ha-scrollbutton"); | ||||
|     if (button !== null) { | ||||
|         if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) { | ||||
|             // button.style.display = "block"; | ||||
|             button.style.pointerEvents = "auto"; | ||||
|             button.style.opacity = "1"; | ||||
|         } else { | ||||
|             // button.style.display = "none"; | ||||
|             button.style.pointerEvents = "none"; | ||||
|             button.style.opacity = "0"; | ||||
| const startup_scrollbutton = function () { | ||||
|  | ||||
|     // Script for showing and acting upon the "scroll to top button" | ||||
|     const scrollFunction = function () { | ||||
|         button = document.getElementById("ha-scrollbutton"); | ||||
|         if (button !== null) { | ||||
|             if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) { | ||||
|                 // button.style.display = "block"; | ||||
|                 button.style.pointerEvents = "auto"; | ||||
|                 button.style.opacity = "1"; | ||||
|             } else { | ||||
|                 // button.style.display = "none"; | ||||
|                 button.style.pointerEvents = "none"; | ||||
|                 button.style.opacity = "0"; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Scroll button | ||||
| if (document.getElementById("ha-scrollbutton") !== null) { | ||||
|     scrollFunction(); | ||||
|     document.getElementById("ha-scrollbutton").addEventListener("click", () => { | ||||
|         document.body.scrollTop = 0; // For Safari | ||||
|         document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||||
|     }) | ||||
|     // TODO: workaround, bc window does not recieve scroll events anymore | ||||
|     setInterval(() => scrollFunction(), 1500); | ||||
| } | ||||
|     // Scroll button | ||||
|     if (document.getElementById("ha-scrollbutton") !== null) { | ||||
|         scrollFunction(); | ||||
|         document.getElementById("ha-scrollbutton").addEventListener("click", () => { | ||||
|             document.body.scrollTop = 0; // For Safari | ||||
|             document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera | ||||
|         }) | ||||
|         // TODO: workaround, bc window does not recieve scroll events anymore | ||||
|         setInterval(() => scrollFunction(), 1500); | ||||
|     } | ||||
| }; | ||||
|  | ||||
| startup_scrollbutton(); | ||||
		Reference in New Issue
	
	Block a user
	 Simon-Martens
					Simon-Martens