2

I need a javascript code that will retreive the Y position of a html object (in this case its "downarrow") so I can use it as a variable. Example:

        var topscrollvalue = // will be the Y of "downarrow"
        function scroll_to(){
        window.scrollTo({
            top: topscrollvalue, //value that will be scrolled
            left: 0,
            behavior:"smooth"
        }
        )
        }

basically i need the "topscrollvalue" variable to be the Y value of "downarrow" object in my html document.

DarKS4ys
  • 23
  • 3
  • 2
    this y position needed is from viewport or from beginning of document? In first case getboudinClientrect() will help you https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect. In second case offser.height will help you – pier farrugia Feb 05 '23 at 16:24
  • I cant thank u enough.I got it working with getBoundingClientRect. – DarKS4ys Feb 05 '23 at 16:49

0 Answers0