Detect when user scrolled down and reached center of page

后端 未结 1 823
灰色年华
灰色年华 2021-01-28 07:14

Currently I have the following code which detects when a user has started scrolling and if they\'ve reached the center of the page.

$(window).scroll(function() {         


        
相关标签:
1条回答
  • 2021-01-28 08:02

    Try this

    $(document).on("scroll.y", function(e) {
      if ($("body").scrollTop() >= ( ($(e.target).height() / 2) -250) ) {
           console.log("approximate center"); $(e.target).off("scroll.y")
      };
      return false
    })
    
    0 讨论(0)
提交回复
热议问题