Dynamically get the distance between the control on the page and the top of the browser

clipboard.png

as shown in the figure, you just want to achieve a fixed header.

my idea is to dynamically listen for the distance from the table to the top of the browser. If the distance is equal to zero, just position the header absolutely at the top.

but what is the way to dynamically monitor the distance from table to the top of the browser?

or is there any other good way to implement it?


handleScroll () {
      // let top = document.querySelector('.editor-warpper')[0].offsetTop
      let top = Offset(document.getElementById('scrolling-container')).top
      let scrolltop = document.body.scrollTop | document.documentElement.scrollTop
      // console.log(top, scrolltop)
      const toolbar = document.querySelector('.ql-toolbar')
      if (scrolltop > top) {
        addClass(toolbar, 'fixedtop')
      } else {
        removeClass(toolbar, 'fixedtop')
      }
    }

if https://developer.mozilla.org.
doesn't have a ladder
/ / rect is a DOMRect object with eight properties: left, top, right, bottom, x, y, width, height
var rect = obj.getBoundingClientRect ();


answer the question of your title:
the height from the top of the visual area + the scrolling height of the scroll bar = the height from the top of the document
gives you a reference


if elementui has a fixed header, don't bother to write

yourself.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4649e-44baf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4649e-44baf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?