Created
February 8, 2022 13:10
-
-
Save daviddarnes/25df15843e204ff45c1a553df6a23cd0 to your computer and use it in GitHub Desktop.
Revisions
-
daviddarnes revised this gist
Feb 8, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ const targetEl = document.querySelector("#theButtonOrElement"); const watchedEl = document.querySelector("#TheElementYoureWatching"); -
daviddarnes created this gist
Feb 8, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ // Back to top button const targetEl = document.querySelector("#theButtonOrElement"); const watchedEl = document.querySelector("#TheElementYoureWatching"); const intersectionObserver = new IntersectionObserver((entries) => { if (entries[0].intersectionRatio > 0) { footerTopButton.setAttribute("data-visible", false); } else { footerTopButton.setAttribute("data-visible", true); } }); if (targetEl && watchedEl) { targetEl.setAttribute("data-visible", false); intersectionObserver.observe(watchedEl); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ [data-visible="false"] { transition: 0.2s; opacity: 0; visibility: hidden; } [data-visible="true"] { opacity: 1; visibility: visible; }