Property 'scrollTop' does not exist on type 'EventTarget'

Viewed 2530

I try to find the position of the Top scroll when I scroll in my body.

document.querySelector('.content').addEventListener('scroll', (e) => {console.log(e)})

when I consult the console.log during the scroll event, it returns me a scrollTop element

....

   scrollHeight: 1205
    scrollLeft: 0
    scrollTop: 300
    scrollWidth: 1743
    shadowRoot: null
    slot: ""**

....

But if I create a constant to capture the value of the scrolltop it gives me an error

const st = e.target.scrollTop;


**TS2339: Property 'scrollTop' does not exist on type 'EventTarget'.**

is there a solution to get the scrollTop value on angular ?

1 Answers

const st = (e.target as HTMLElement).scrollTop;

Related