Javascript 确定是否在div中滚动到底部

Javascript 确定是否在div中滚动到底部,javascript,jquery,css,ember.js,Javascript,Jquery,Css,Ember.js,我有一个ember应用程序。在这个应用程序中,我在导航栏中有一个图标,单击该图标时会显示一个带有通知的下拉列表。我已经将下拉列表的最大高度设置为390px。现在我想确定用户何时到达下拉列表的底部,以便我可以对服务器进行ajax调用以获取更多数据 html js 当我使用$('.ps content').height时,它给出了390px。如何将整个内容高度渲染到下拉列表中 在“viewPortTop”中,我得到了多少用户已滚动。但我无法确定“distanceToViewportTop”应该做什么

我有一个ember应用程序。在这个应用程序中,我在导航栏中有一个图标,单击该图标时会显示一个带有通知的下拉列表。我已经将下拉列表的最大高度设置为390px。现在我想确定用户何时到达下拉列表的底部,以便我可以对服务器进行ajax调用以获取更多数据

html

js

当我使用$('.ps content').height时,它给出了390px。如何将整个内容高度渲染到下拉列表中


在“viewPortTop”中,我得到了多少用户已滚动。但我无法确定“distanceToViewportTop”应该做什么因此,当用户到达底部时,差异为零。我不能使用documnet高度和窗口高度,因为它占据整个页面高度。对于整个页面,它是documnet-窗口高度以获得底部页面。对于div,我应该怎么做

您可以使用一些属性/方法:

$().scrollTop()//how much has been scrolled
$().innerHeight()// inner height of the element
DOMElement.scrollHeight//
元素内容的高度

所以你可以取前两个属性的和,当它等于最后一个属性时,你就到了终点:

jQuery(function($) {
    $('#flux').on('scroll', function() {
        if($(this).scrollTop() + $(this).innerHeight() >= $(this)    [0].scrollHeight) {
            alert('end reached');
        }
    })
});

didInsertElement: function(){
    $('.ps-content').on('scroll', $.proxy(this.didScroll, this));
  },
  willDestroyElement: function(){
    $('.ps-content').off('scroll', $.proxy(this.didScroll, this));
  },

  didScroll: function(){
    if (this.isScrolledToBottom()) {
      this.sendAction('loadMore');
    }
  },

  // we check if we are at the bottom of the page
  isScrolledToBottom: function(){
      var distanceToViewportTop = WHAT SHOULD I AM DO HERE ?
      var viewPortTop = $('.ps-content').scrollTop();
      if (viewPortTop === 0) {
        return false;
      }   
      return (viewPortTop - distanceToViewportTop === 0);
  },
$().scrollTop()//how much has been scrolled
$().innerHeight()// inner height of the element
DOMElement.scrollHeight//
jQuery(function($) {
    $('#flux').on('scroll', function() {
        if($(this).scrollTop() + $(this).innerHeight() >= $(this)    [0].scrollHeight) {
            alert('end reached');
        }
    })
});