search

Home  >  Q&A  >  body text

javascript - js function code, about scrolling loading data


Can you explain the meaning of this code in detail?
Scroll initialization is true

伊谢尔伦伊谢尔伦2704 days ago740

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-07-05 10:47:13

    The function you gave should be a method in a module, and it needs to be viewed together with other attributes or methods in this module.
    Just look at this method. This method should exist as a callback function for an event (probably a scroll event). When this event is triggered, this method is executed. There are two situations
    (1) this.scroll is true and enters the specific logic

    totalheight与body...作比较 实际上是页面已显式高度,和页面内容实际高度做比较
    简单点说就是滚动条是否快到底部了,如果满足条件进入下面的逻辑,做这么几件事
        已显式页面+1,this.scroll置为false,进行判断,已显示页面是否小于5,如果是加载下面的页面

    (2) this.scroll is false and the above logic is not executed
    // This code lacks the logic to set this.scroll back to true. I think it is in getAjaxData. The advantage of doing this is that when loading new When the page is scrolling, the listening event is temporarily invalid and will not cause the same request to be issued repeatedly

    reply
    0
  • 怪我咯

    怪我咯2017-07-05 10:47:13

    Just scroll to the bottom and there is still 200 distance, start loading the data once, wait for the data rendering to complete, and resume. Recycle

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-07-05 10:47:13

    I guess you want to ask why this initial flag is set?
    It should be to prevent multiple ajax requests for one scroll.

    reply
    0
  • Cancelreply