0

I'm using an UP button(upArrow) and a DOWN button (downArrow) to scroll a div. The code works fine. Below is the code set for those 2 buttons.

My question is, how do I join this when someone uses the mouse wheel to scroll?

Example: If someone uses the downArrow button to scroll down and reach at the bottom a pop-up shows ( if( val == (items) ){ //reasched end - now do something... } ). Now how do I make the popup show if someone uses the mouse wheel and instead of the buttons?

var numVal = 0,
    val = 0,
    items = 12,
    scrollVal = 300;
$('#downArrow').click(function() {
    numVal = numVal+scrollVal;
    val++;
    $("#itHolder").animate({
        scrollTop: numVal
    });
    if( val == (items) ){
         //reasched end - now do something...
     }
});
$('#upArrow').click(function() {
    numVal = numVal-scrollVal;
    val--;
    $("#itHolder").animate({
        scrollTop: numVal
    });
    if( val == 0 ){
        //reasched top - now do something...
    }
});
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Becky
  • 5,467
  • 9
  • 40
  • 73

1 Answers1

0

You could combine listening for the scrolling event on your containing div, with its scrollTop property to find when you hit the bottom...

$(myContainingDiv).on('scroll', function () {
    if (this.scrollTop() == this.height()) {
        // Do Something...
    };
});
HeyHeyJC
  • 2,627
  • 1
  • 18
  • 27