Advertisement
Guest User

Untitled

a guest
Nov 14th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const positionArray = [500, 1500, 2200, 3100]
  2. const derivePositionIndex = (scrollPosition) => {
  3.     let positionIndex = null // Insert default value
  4.     positionArray.some((d, i) => {
  5.         if (scrollPosition <= d) {
  6.             positionIndex = i
  7.             return true
  8.         }
  9.         return false
  10.     })
  11.     return positionIndex
  12. }
  13.  
  14. const scrollPositionY = 1700 // Test value. Replace with actual value
  15. const derivedPositionIndex = derivePositionIndex(scrollPositionY)
  16. console.log("Position index:", derivedPositionIndex)
  17. console.log("Element position:", positionArray[derivedPositionIndex])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement