Jquery infinite scroll - with div not scrollbar of body

前端 未结 3 1595
半阙折子戏
半阙折子戏 2020-12-04 23:07

Suppose I have div and I want to fetch data and push data into that div. When the user scrolls within the div, the next set of data will be fetched and pushed into the div.

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 23:33

    I think .scrollTop() is your weapon of choice. jQuery API

    Get the current vertical position of the scroll bar for the first element in the set of matched elements.

    So make sure to bind it to the right element. Directly on the div should work I guess.

    The vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. If the scroll bar is at the very top, or if the element is not scrollable, this number will be 0.

    So probably you've to find a way to calculate the height of the div as if it would be stretched without scrollbar to put these to numbers in a meaningful relation to shoot of the loading event.

提交回复
热议问题