1

For a chat app, I wanted to know if my ion-content is scrolled at bottom, to scroll down again after adding a message only if the user is already at bottom.

It it any possibility to easily detect when the content is scrolled?

3
  • You have provided no code from your application and made no clear attempt at trying to solve it yourself or research the issue. If you hadn't of immediately answered your own question, how did you expect anyone to help when there's nothing to work from? That is why I down voted. Commented Apr 14, 2016 at 14:57
  • 1
    Yeah, but SO provide a way to answer your own questions, to help the community, and I think the answer is quite self explanatory for anyone who use Ionic... Try asking a new question : don't you see the checkbox at the bottom of the form: "Answer your own question – share your knowledge, Q&A-style"? Commented Apr 14, 2016 at 18:37
  • 3
    Here is what happened: I searched for around half an hour, without finding any solution on SO. When I figured out something, I though it should be good to share it with other. Please don't judge too fast, man. Commented Apr 14, 2016 at 18:38

2 Answers 2

9

Looking at $ionicScrollDelegate.getScrollView(), I found a __maxScrollTop property.

The answer is quite simple:

var scrollTopCurrent = $ionicScrollDelegate.getScrollPosition().top;
var scrollTopMax = $ionicScrollDelegate.getScrollView().__maxScrollTop;
var scrollBottom = scrollTopMax - scrollTopCurrent;

if (!scrollBottom) {
  $ionicScrollDelegate.scrollBottom(true);
}

You can even add some tolerance by checking if scrollBottom is lower than your tolerance limit.

Sign up to request clarification or add additional context in comments.

2 Comments

You asked and answered your own question literally seconds apart?
This is why there is a "Answer your own question – share your knowledge, Q&A-style" checkbox... To help others because I have to search for half an hour before I find a solution... So why the downvote?
1

we can use on-scroll or on-scroll-complete events on content then we need to call function in controller like below

 $scope.checkScroll = function() {
     var currentTop = $ionicScrollDelegate.getScrollPosition().top;
     var maxTop = $ionicScrollDelegate.getScrollView().__maxScrollTop;
     if (currentTop >= maxTop) {
     // hit the bottom

    }
};

Complete tutorial is given here http://freakyjolly.com/detect-ionic-view-page-bottom-load-infinite-data/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.