Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite scrolling in both directions - Up and down

I am trying to create a page that is an endless scrolling loop both up and down.

At the moment I am using jquery to relocate content from the top of the page to the bottom. This creates a nice seemless loop when you scroll down but I would like it to work when the user scrolls up too.

The problem seems to be that even if content is positioned in negative vertical space on the page the scroll will not extend to that space. As far as I am aware there is no way to override this so I am looking for some type of work around.

I have thoughts of using javascript to disable the scrolling and using the scroll event to reposition the elements but there are already lots of absolute positioned elements and animation happening on the page so I'm concerned about performance taking that route.

Any other leads?

like image 405
Joe Hamilton Avatar asked May 13 '12 09:05

Joe Hamilton


People also ask

What is endless scrolling called?

Infinite scroll is a user experience (UX) practice in which content continually loads when a user reaches the bottom of the page. This creates the experience of an endless flow of information on a single, seemingly never-ending page.

What does continuous scrolling mean?

With the Continuous Scrolling, new data is automatically retrieved as the user has scrolled to the bottom of the page. It thus appears as if the page has no end, as more data will be loaded and inserted into the page each time the user scrolls to the bottom of page.

How do you do continuous scrolling?

How to scroll continuously. To use auto-scrolling, click the scroll wheel by pushing in on the wheel on a blank or empty portion of the screen. Once clicked, one of the three scrolling cursor icons (shown to the right) are shown, depending on the program you're using.

How do I stop continuous scrolling?

Scroll down to the end of the "Browsing" section. Uncheck "Use smooth scrolling" and click "OK."


2 Answers

OK... I worked it out.

I adapted this script which instantly relocates the scroll location to the top of the page when you get to the bottom and to the bottom when you reach the top.

$(window).scroll(function() {
    if ( $(window).scrollTop() >= 18830 ) {
        $(window).scrollTop(201);
    }
    else if ( $(window).scrollTop() == 0 ) {
        $(window).scrollTop(18629);
    }    
});

And then I made sure that the content at the bottom and the top of the page was identical. I thought that there would be a flash or something when this relocation happened but it's smooth!

like image 131
Joe Hamilton Avatar answered Oct 10 '22 00:10

Joe Hamilton


The solution I like the best is this one (code), because it adds elements at the bottom before the bottom is reached, making sure that scrolling remains continuous (even with smooth scrolling on). However, it doesn't work that well on mobile phones where scrolling can happen pretty quickly. I recommend Marijn Haverbeke's wonderful article on fake scrollbars in CodeMirror where he deals with similar issues.

I leave you with some snippets.

First, some background. Why would we want to fake a scrollbar to begin with?

In order to remain responsive when huge documents are loaded in, CodeMirror does not render the whole document, but only the part of it that is currently scrolled into view. This means that the amount of DOM nodes it creates is limited by the size of the viewport, and the browser relayouts triggered by changes to the text are relatively cheap.

And further down...

Then, it listens to wheel events, but never calls preventDefault on them or does scrolling in response to them. Instead, it responds by setting a timeout to observe the amount of pixels that the wheel event did scroll the content, and uses that to tweak its delta-to-pixel rate at run-time.

like image 35
Andres Riofrio Avatar answered Oct 10 '22 02:10

Andres Riofrio