2

I got directive for getting scrolling event, but I wanna scroll down event only.

.directive('whenScrolled', function() {
    return function(scope, elm, attr) {
        var raw = elm[0];

        elm.bind('scroll', function() {
            if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
                scope.$apply(attr.whenScrolled);
            }
        });
    };
})
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • You can use this answer to know the direction of the scroll: https://stackoverflow.com/a/31223774/5751251 – DSCH Nov 15 '17 at 10:33
  • try this..https://codepen.io/razvan-tudosa/pen/GZKNzR – Jayanti Lal Nov 15 '17 at 10:39
  • Can you please tell me about properties like "scroll" in line elm.bind('scroll', function() , for scroll down? – Shivam Sharma Nov 15 '17 at 10:42
  • If you solved your problem, please post your answer so that others can use it. See [Can I answer my own question?](https://stackoverflow.com/help/self-answer). – georgeawg Nov 15 '17 at 17:19

1 Answers1

0

I have resolved this problem by the following code.

//=========================================================================
// Custom Infinite Scoller for table edit 
//=========================================================================
.directive('whenScrolled', function() {
    return function(scope, elm, attr) {
        var raw = elm[0];

        ̶e̶l̶m̶.̶b̶i̶n̶d̶(̶'̶w̶h̶e̶e̶l̶'̶,̶ ̶f̶u̶n̶c̶t̶i̶o̶n̶(̶)̶ ̶{̶
        elm.bind('wheel', function(event) {
            var delta;
            if (event.wheelDelta){
                delta = event.wheelDelta;
            }else{
                delta = -1 *event.deltaY;
            }
            if (delta < 0){
                //call whenScrolled attribute to HTML for calling function from controller --- Scroll Up
                scope.$apply(attr.whenScrolled);

            }else if (delta > 0){
                //do nothing --- Scroll Down
            }
        });

    };
})
georgeawg
  • 48,608
  • 13
  • 72
  • 95