Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const positionArray = [500, 1500, 2200, 3100]
- const derivePositionIndex = (scrollPosition) => {
- let positionIndex = null // Insert default value
- positionArray.some((d, i) => {
- if (scrollPosition <= d) {
- positionIndex = i
- return true
- }
- return false
- })
- return positionIndex
- }
- const scrollPositionY = 1700 // Test value. Replace with actual value
- const derivedPositionIndex = derivePositionIndex(scrollPositionY)
- console.log("Position index:", derivedPositionIndex)
- console.log("Element position:", positionArray[derivedPositionIndex])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement