goose
goose

Reputation: 74

get value of current scroll position by js

I need if user scrolled to <a id="stass"> this script runs

<script>
if(current id is stass){
      var stassik = 1231;

}
</script>
The part with if(current id is stass) it s where I need to get info about current anchor. I mean, if user scrolled to this anchor, the var stassik will become 1231

Upvotes: 0

Views: 59

Answers (1)

Shijil Narayanan
Shijil Narayanan

Reputation: 1019

Try using IntersectionObserver API to achieve this. For more details: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API

Upvotes: 1

Related Questions