Last active
October 19, 2022 17:31
-
-
Save jeziellopes/1940e5c754f1c62f05cb76d852d2c4c2 to your computer and use it in GitHub Desktop.
This file contains 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
// get current element ref | |
const ref = useRef(null) | |
// persist index | |
let sectionIndex: number | |
// helper to get element index from the DOM | |
const getElementIndex = () => { | |
// if (sectionIndex) { | |
// console.log({ sectionIndex }) | |
// return sectionIndex | |
// } | |
// TODO: give credits | |
// https://stackoverflow.com/a/11762035 | |
// get nodes from j-scroll container | |
const nodes = Array.prototype.slice.call( | |
document.getElementById(`j-scroll-container`)?.children || {} | |
) | |
const index = nodes.indexOf(ref.current) | |
if (index > 0) { | |
sectionIndex = index | |
} | |
// return index | |
return sectionIndex | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment