search

Home  >  Q&A  >  body text

javascript - $(document).scrollTop() and $('#js_productWrap').offset().top of a certain div

The difference between $(document).scrollTop() and $('#js_productWrap').offset().top of a certain p

过去多啦不再A梦过去多啦不再A梦2736 days ago1119

reply all(2)I'll reply

  • 三叔

    三叔2017-06-29 10:12:12

    When the document is longer than the computer screen, the browser can only view part of it, which is equivalent to a viewfinder. The distance from this frame to the top of the document is scrollTop

                     a document
             ^     +-----------+    ^
             |     |           |    |
             |     |           |    |scrollTop
             |     |           |    |
             |     |           |    |
    offsetTop|     |  viewport |    |
             |  +-----------------+ v
             |  |  |           |  |
             v  |  +--+ #js_productWrap
                |  |  |        |  |
                |  +--+        |  |
                |  |           |  |
                +-----------------+
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   |           |
                   +-----------+
    

    reply
    0
  • 怪我咯

    怪我咯2017-06-29 10:12:12

    $(document).scrollTop() returns the height of the current web page when it is scrolled;
    $('#js_productWrap').offset().top returns the height of the target element from the top of the document

    reply
    0
  • Cancelreply