javascript - $(document).scrollTop() and $('#js_productWrap').offset().top of a certain div
过去多啦不再A梦
过去多啦不再A梦 2017-06-29 10:10:12
0
2
1087

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

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
三叔

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
            |  |  |        |  |
            |  +--+        |  |
            |  |           |  |
            +-----------------+
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               |           |
               +-----------+
刘奇

$(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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template