In my script I load some posts from external RSS feeds. I have a “load more” button that when it is clicked, calls the loadfeed() function and shows some 10 more posts.
When this happens, there is a slideTo() that slides the browser to the first of the new posts list.
In addition to the “load more” button, I have a timer that checks for any new posts of those feeds. This happens every 3 minutes.
As I said, if you click on the “load more” button, the page is moved with the first new post on the top of your screen. The problem here is that this sliding happens also if you clicked once the “load more” button, you read the articles, and as you read the 3 minutes are passed, you slide back to the first post of the new list you loaded. More specific, when you load (from the default 20) +10 more posts, you will be slided to the 21st post after 3 minutes.
So my question here it is how to avoid this?
this is the #loadmore button that calls loadfeed()
$("#loadmore").click(function() {
cap += 10;
loadfeed();
});
and this is a part of loadfeed() that handles sliding. I have an if statement for the sliding to happen after the default 20 posts. Without this you will be slide to the 11 post after 3 minutes and no “load more” is clicked.
if (cap > 20) {
$(".p" + (cap-9)).slideto({
slide_duration : 'slow'
});
}
Forgive me if I’ve misunderstood, but can’t you just pass a parameter to
loadfeed()?In
$("#loadmore").click, callloadfeed(true)and for the timer callsetTimeout(function () { loadfeed(false); }, 12000);. Or similar.Edit:
I don’t know which slideto plugin you’re using. I’ve downloaded 2 of them, but neither works as yours seems to. I have got this to work with the scrollTo plugin.
In this code, I’ve removed all of the AJAX bits and some other things that didn’t seem relevant to the question. The basic changes are to add a parameter to
loadfeed()that tells it whether or not to scroll when adding new content. Clicking the button makes it scroll to the bottom; waiting for the timer does not. (I’ve also added a clearTimeout to stop the timer triggering multiple times if someone goes crazy with the load button.)