0

I needed to get scroll position of div, so I found onScroll event in react documentation, use it in my code and in developer tool found properties that I needed. In documentation I found some words:

Event names: onScroll Properties: number detail DOMAbstractView view 

Many times I come across a situation when I do not understand why something is written in the documentation and how to use it. Could someone help me and explain what this documentation is saying?

1 Answer 1

2

What the documentation is saying is that if you capture the onScroll event, that event object will have at least two properties, including detail and view. For example, this means that you can do:

function onScrollHandler(event) { console.log(event); console.log(event.detail); console.log(event.view); } 

Specifically, detail will be of type number and view will be of type DOMAbstractView

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, but I don't understand yet what does property detail means? I'm trying console.log(event.detail) and getting 0 every time. And one more thing - event object have a lot of other properties. For me it's strange - mention about two properties and tell anything about others.
Yes, 0 is a number, and as the docs say, event.detail is of type number. What exactly that number means I don't know - link to the docs and maybe I can find it there. And as I said, events has lots of things, and all the docs are saying is that event will have at a minimum the detail and view attributes. The event itself is a complicated thing, giving you lots of information about the event. Go learn about DOM events to see what you can do with them.
So, this documentation explains the base fields of the event. As you can see, the spec shows that event.detail will always be 0. It seems to me that the event.detail property actually comes from the mouse event category, which kind of makes sense if you think of a scroll event being an extension of the mouse event, but you don't click to do a scroll so the number of clicks is always 0.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.