Om3ga
Om3ga

Reputation: 32823

find out if user is still scrolling after reaching to the bottom/top of the div

I following code which works fine to find when user reaches to the bottom or top of the div while scrolling. However, now I want to find once the user is reached to the bottom/top of the div tag and he/she is still scrolling. I mean once user reaches to the bottom the find out if that user is still scrolling in bottom direction and if user reaches to the top the find out if he is still scrolling in up direction. How can I achieve this?

Here is the CODE

$('.scroll').on('scroll',checkScroll);


function checkScroll(e)
{
    var elem = $(e.currentTarget);
    if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) 
    {
        console.log("bottom");
    }

    if (scrollBottom(elem) == elem.outerHeight()) 
    {
        console.log("top");
    }

}

function scrollBottom(el)
{
    return $( el ).scrollTop() + $( el ).height();
}

Upvotes: 0

Views: 124

Answers (1)

Umesh Sehta
Umesh Sehta

Reputation: 10683

try this i have test only in chrome browser:-

$('.scroll').bind('mousewheel DOMMouseScroll', function(event){
var elem=  $(this);
   if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) 
   {
        console.log("opps.. still scrolling");           
   }
});

Demo

Upvotes: 1

Related Questions