Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect div scroll bar hit the top

how to detect when div scroll bar, scroll up and hit the top(only when it hit the top)

I have found another post, but this one is hit the bottom.

what i need is hit the top. anyone know how to change this?

$("#divID").scroll(function(){
    if($(this)[0].scrollHeight - $(this).scrollTop() <= $(this).outerHeight())
    {
        alert(1);
    }
});

Know when vertical scrollbar hits bottom of scroll in div

like image 540
Ben Avatar asked Jan 21 '26 16:01

Ben


1 Answers

working fiddle

var el = $('.test');
el.on('scroll', function(){

    if(el.scrollTop() == 0){alert("i just hit the top")}


});
like image 161
HIRA THAKUR Avatar answered Jan 24 '26 04:01

HIRA THAKUR