Open fri3ndly opened 12 years ago
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.
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.
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.
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?
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. :)
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; };
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; };
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
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.
@CC90 Thank you :) Maybe can you add an argument to enable or disable the "up scrolling" and create a PR ?
@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.
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') { } }