/*
Visual representation of the approach:
--------
--------
--------
--------
--------
--------
--------
--------
--------
--------
--------
--------
--------
--------
--------
==================================================
[=] - real scrollable height (h)
[-] - "pages"; total height of all (n) pages is (th) = (ph) * (n)
The overlap between pages is (cj) and is the distance the scrollbar
will jump when we adjust the scroll position during page switch.
To keep things smooth, we need to minimize both (n) and (cj).
Setting (ph) at 1/100 of (h) is a good start.
*/
var th = 100000; // virtual height
var h = 100000; // real scrollable height
var ph = h / 100; // page height
var n = Math.ceil(th / ph); // number of pages
var vp = 400; // viewport height
var rh = 600; // row height
var cj = (th - h) / (n - 1); // "jumpiness" coefficient
var page = 0; // current page
var offset=0; // current page offset
var prevScrollTop = 0;
var rows = {}; // cached row nodes
var horizontalRows = {};
var viewport, content;
$(function() {
viewport = $("#viewport");
content = $("#content");
horizontalContent = $(".sticky-track");
viewport.css("height",vp);
content.css("height",h);
horizontalContent.css("width", h);
viewport.scroll(onScroll);
viewport.trigger("scroll");
});
function onScroll() {
var scrollTop = viewport.scrollTop();
if (Math.abs(scrollTop-prevScrollTop) > vp)
onJump();
else
onNearScroll();
renderViewport();
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.