Last active
March 10, 2022 19:40
-
-
Save khleomix/21637740af44b7ba11ef921010006f85 to your computer and use it in GitHub Desktop.
Smooth Scroll to div on load
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
/** | |
* File search.js | |
* | |
* Scroll to div on load. | |
* | |
*/ | |
const divToScroll = document.getElementById( 'scroll-here' ); | |
document.addEventListener( 'DOMContentLoaded', function ( event ) { | |
if ( divToScroll ) { | |
divToScroll.scrollIntoView( { | |
behavior: 'smooth', | |
block: 'start', | |
inline: 'nearest', | |
} ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment