Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Supporting full page scrolling. #11

Open
SimeonC opened this issue Nov 12, 2015 · 1 comment
Open

Supporting full page scrolling. #11

SimeonC opened this issue Nov 12, 2015 · 1 comment

Comments

@SimeonC
Copy link

SimeonC commented Nov 12, 2015

I needed for my app to support full page scrolling so I've modified your directive to support "target" attribute. (Sorry I don't have time to do a PR). The following code supports both scrolling an element other than the current one (if you use routes and need to target a parent) and the special case of the whole page scrolling - 'window'.

Full code is in this gist: https://gist.github.com/SimeonC/a15055a5b9ec0c5685da.
Highlights below:

Inserted at Line 12:

bindTarget = element,
calculateRemaining = function(){
    return element[0].scrollHeight - (element[0].clientHeight + element[0].scrollTop);
};

if (attr.target) {
    if (attr.target.toLowerCase() === 'window') {
        bindTarget = angular.element(window);
        element = angular.element(document.querySelector('body'))
        calculateRemaining = function(){
            return element[0].offsetHeight - (window.pageYOffset + window.innerHeight);
        };
    }
    else element = angular.element(document.querySelector(attr.target));
}

Line 35:

bindTarget.bind(
    'scroll', function () {
        var remaining = calculateRemaining();
        //if we have reached the threshold and we scroll down
@joelcdoyle
Copy link

I would also love to be able to listen to the full page scroll position. However, this method doesn't work so well when using the angular routing features. Each time you navigate away and then back to the route that contains the infinite scroll directive, a new scope is created for the directive resulting in multiple listeners calling your handler. I'm not sure if this is a symptom of lrInfiniteScroll, itself or this gist.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants