Last active
November 3, 2023 20:47
-
-
Save fahdi/0397fe2d5575adda91dc063d8c6f7c5b to your computer and use it in GitHub Desktop.
Revisions
-
fahdi revised this gist
Nov 3, 2023 . No changes.There are no files selected for viewing
-
fahdi renamed this gist
Nov 3, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
fahdi renamed this gist
Nov 3, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
fahdi revised this gist
Nov 3, 2023 . 2 changed files with 12 additions and 9 deletions.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,10 +1,13 @@ let timeout; window.addEventListener('scroll', function() { clearTimeout(timeout); timeout = setTimeout(function() { var header = document.querySelector('header.sticky.on-scroll'); var headerRect = header.getBoundingClientRect(); if (headerRect.top === 0) { header.classList.add('sticking'); } else { header.classList.remove('sticking'); } }, 100); // Adjust the timeout value to find a good balance between responsiveness and performance }); 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,3 +1,3 @@ .sticking { box-shadow: none !important; } -
fahdi revised this gist
Nov 1, 2023 . 1 changed file with 4 additions and 4 deletions.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,9 +1,9 @@ window.addEventListener('scroll', function() { var header = document.querySelector('header'); // Replace 'header' with the appropriate selector for your header element var headerRect = header.getBoundingClientRect(); if (headerRect.top === 0) { header.classList.add('middle-class'); // Add the class when the header is touching the top } else { header.classList.remove('middle-class'); // Remove the class otherwise } -
fahdi revised this gist
Nov 1, 2023 . 1 changed file with 1 addition 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 @@ -2,7 +2,7 @@ window.addEventListener('scroll', function() { var header = document.querySelector('header'); var scrollPosition = window.pageYOffset; if (scrollPosition > 0) { header.classList.add('middle-class'); // Add the class when the header is at the top } else { header.classList.remove('middle-class'); // Remove the class otherwise -
fahdi revised this gist
Nov 1, 2023 . 1 changed file with 4 additions and 6 deletions.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,12 +1,10 @@ window.addEventListener('scroll', function() { var header = document.querySelector('header'); var scrollPosition = window.pageYOffset; if (scrollPosition <= 0) { header.classList.add('middle-class'); // Add the class when the header is at the top } else { header.classList.remove('middle-class'); // Remove the class otherwise } }); -
fahdi revised this gist
Nov 1, 2023 . 1 changed file with 3 additions and 0 deletions.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,3 @@ .middle-class { box-shadow: none !important; } -
fahdi created this gist
Nov 1, 2023 .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,12 @@ window.addEventListener('scroll', function() { var header = document.querySelector('header'); // Replace 'header' with the appropriate selector for your header element var scrollPosition = window.pageYOffset; var windowHeight = window.innerHeight; var headerHeight = header.offsetHeight; if (scrollPosition > 0 && scrollPosition < (document.body.offsetHeight - windowHeight - headerHeight)) { header.classList.add('middle-class'); // Replace 'middle-class' with the desired class name } else { header.classList.remove('middle-class'); } });