Ionic framework 离子-如何确定滚动是否在内容的底部

Ionic framework 离子-如何确定滚动是否在内容的底部,ionic-framework,ionic2,Ionic Framework,Ionic2,我的应用程序中有一些聊天功能,当输入新消息时,它会自动滚动到的底部,但是,与许多聊天应用程序一样,如果您在聊天中向上滚动以阅读最新消息之前的内容,我不希望滚动。只有当用户处于屏幕的最底部时,我才会在收到新消息后滚动到底部。我还没有解决这个问题 这是我目前的代码: scrollToBottom() { // If the scrollTop is greater than the height, we are at the bottom, // in which case, show s

我的应用程序中有一些聊天功能,当输入新消息时,它会自动滚动到
的底部,但是,与许多聊天应用程序一样,如果您在聊天中向上滚动以阅读最新消息之前的内容,我不希望滚动。只有当用户处于屏幕的最底部时,我才会在收到新消息后滚动到底部。我还没有解决这个问题

这是我目前的代码:

scrollToBottom() {

  // If the scrollTop is greater than the height, we are at the bottom,
  // in which case, show scrolling animation
  let dimensions = this.content.getContentDimensions();
  let scrollHeight = dimensions.scrollHeight;
  let scrollTop = dimensions.scrollTop;
  let contentHeight = dimensions.contentHeight;
  let heightAndScrollTop = contentHeight + scrollTop;

  // This is the best I can get, assuming that the screen is in a consistent dimension, which we all know is basically non-existent due to all the different types of screens
  if((scrollHeight - heightAndScrollTop) <= 39 && (scrollHeight - heightAndScrollTop) >= 0) { 
    this.content.scrollToBottom(300);
  }
}
scrollToBottom(){
//如果scrollTop大于高度,则我们位于底部,
//在这种情况下,显示滚动动画
设dimensions=this.content.getContentDimensions();
设scrollHeight=dimensions.scrollHeight;
设scrollTop=dimensions.scrollTop;
设contentHeight=维度。contentHeight;
让heightAndScrollTop=内容高度+scrollTop;
//这是我能得到的最好的结果,假设屏幕处于一个一致的维度,我们都知道由于所有不同类型的屏幕,这个维度基本上是不存在的
如果((scrollHeight-heightAndScrollTop)=0{
这个.content.scrolltobttom(300);
}
}

知道我能做些什么来解决这个问题吗?

首先,在内容底部创建一个元素:

<ion-content>
    //Your messages go here
    ...
    <div id="check-point"></div>  <-- Notice this element
</ion-content>

最后,每当推送新消息时,检查
检查点
是否在视口中。如果是,则表示用户位于页面底部。如果否,则表示用户不是

这似乎不是基于事件的。我们如何自动运行IsElementViewPort?@DFSFOT什么意思
自动
?每次要检查元素是否在视口中时,都需要手动启动
IsElementViewPort(…)
。以某种方式使这种基于事件的(观察者模式)可以让您停止手动触发它,从而使其成为自动的。
   //This function just check if element is fully in vertical viewport or not
   isElementInViewPort(element: HTMLElement,  viewPortHeight: number) {
      let rect = element.getBoundingClientRect(); 
      return rect.top >= 0  && (rect.bottom <= viewPortHeight);
   }