Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to disable upward scrolling? #30

Open
fri3ndly opened this issue Jul 20, 2012 · 11 comments
Open

Any way to disable upward scrolling? #30

fri3ndly opened this issue Jul 20, 2012 · 11 comments

Comments

@fri3ndly
Copy link

I have got this script working great via ajax now and loading products as the user scrolls down. However when scrolling back to the top the script tries to load products again.

I thought something like this might fix it but it hasn't:

callback: function(fireSequence, pageSequence, scrollDirection)
{
if (scrollDirection == 'next')
{
}
}

@fredxinfan
Copy link

Same problem here, it would be good if given an ability to disable the upward scrolling.
I used the following to disable content loading upwards:

content: function(i, p, d) {
if(d=="next"){
return "Something"
}else{
return false
}

        }

It worked, but it still bumped back a bit and that makes people very hard to see the top text.

@fredxinfan
Copy link

I finally worked out by comment out this line in detectScrollDirection function:

this.scrollDirection = 'prev';

It's in else block, line number is 177, hope that helps.

@fredwu
Copy link
Owner

fredwu commented Aug 29, 2012

Hi, for now if you're having problems with upscrolling, please use version 1.6.0.

I'm in the process of rewriting the plugin.

@fredxinfan
Copy link

Hi, thanks all your work Wu !
I've got something else to ask if that's ok ? I'm not sure for what reason you merge options by doing this:

this.options = $.extend({}, defaults, options);

It's gonna make the plugin ignores the value specified by insertAfter attribute and always use default instead, anyway, I resolved this for myself by change it to:

this.options = $.extend(defaults, options);

as you can see, I removed the empty hash at the front and that worked for me, but you might have your own reasons. So not sure if you can enlighten me on that?

@fredwu
Copy link
Owner

fredwu commented Aug 30, 2012

Hmmm, interesting. I can't remember if there was a particular reason for that - it might actually just be an oversight, I'll change that for the next release. :)

@alexsegura
Copy link

Here is how I disabled it with version 1.8: I redefined the scrollableAreaMargin function to do nothing when hitting top

// Disable prev scroll
EndlessScroll.prototype.scrollableAreaMargin = function(innerWrap, target) {
    var margin;
    switch (this.scrollDirection) {
        case 'next':
            margin = innerWrap.height() - $(target).height() <= $(target).scrollTop() + this.options.inflowPixels;
            if (margin) {
                target.scrollTop(innerWrap.height() - $(target).height() - this.options.inflowPixels);
            }
            break;
            case 'prev':
                margin = $(target).scrollTop() <= this.options.inflowPixels;
                // Don't call target.scrollTop
    }
    return margin;
};

@CC90
Copy link

CC90 commented Jan 8, 2013

Hi, this can be fixed:

In the Method "detectScrollDirection", manually change "didScroll" back to false. Method "shouldTryFiring" will then always return false --> no Event is fired

EndlessScroll.prototype.detectScrollDirection = function() {
    var currentScrollTop;
    this.didScroll = true;
    currentScrollTop = $(this.target).scrollTop();
    if (currentScrollTop > this.lastScrollTop) {
      this.scrollDirection = 'next';
    } else {
      this.scrollDirection = 'prev';
      this.didScroll = false; //THIS HERE will cause "shouldTryFiring" to return false
    }
    return this.lastScrollTop = currentScrollTop;
  };

@tim-peterson
Copy link

I actually found I needed to revert back to version 1.4.4 to prevent scrolling up from loading the entire page over again. Just to be clear, "Scrolling up" also means when you start at the top of the page and "pull (down) to refresh" like you do on the iPhone.

Here's endless-scroll.js v.1.4.4: https://gist.github.com/tim-peterson/5090646

@erquhart
Copy link

erquhart commented May 9, 2013

Great work here! Upward scrolling does seem a bit of a sore spot - any consideration of just removing it entirely? For anyone else dealing with this, CC90's method (two posts up) worked like a charm, using version 1.8.

@Hakadel
Copy link

Hakadel commented Sep 3, 2013

@CC90 Thank you :) Maybe can you add an argument to enable or disable the "up scrolling" and create a PR ?

@dennislo
Copy link

@CC90 Thank you for the fix. The code snippet successfully disabled upward scrolling.

If anyone is interested, I've forked this "endless scroll" v1.8.0 and created v1.9.0 which disables upward scrolling. It is at https://github.com/dennislo/jquery-endless-scroll.

To install it in your project, run the following on your terminal:

bower install --save jquery-endless-scroll-dlo

This will download it to your bower_components folder and saves a reference to your bower.json file.

If @fredwu creates v2.0.0 I'll be aiming to remove this fork.

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

No branches or pull requests

9 participants