Created
April 1, 2025 00:46
-
-
Save alokstha1/0dc22d3af59478803b84993f2ebe4087 to your computer and use it in GitHub Desktop.
Javascript to Scroll to a certain section
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 characters
function scrollToDivFromHash() { | |
const hash = window.location.hash; | |
if (hash) { | |
const targetId = hash.substring(1); // Remove the '#' | |
const targetDiv = document.getElementById(targetId); | |
if (targetDiv) { | |
targetDiv.scrollIntoView({ behavior: 'smooth' }); // Smooth scrolling | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment