Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

This code is an alternate version of the code found in my tutorial on Nettuts+: http://net.tutsplus.com/tutorials/javascript-ajax/implement-twitter-scrolling-without-jquery-2

View twitter-scrolling.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
$(document).bind("scroll", function (e) {
scrolling = true;
});
 
setInterval(function () {
if (scrolling) {
//console.profile("scroll");
scrolling = false;
var temp_top = win.scrollTop(),
down = scroll_top - temp_top < 0 ? true : false,
top_item = null, child, style, i = 0, distance = 0;
 
scroll_top = temp_top;
if (prev_item) {
height = height || prev_item.offsetHeight;
if ( down && get_top_offset(prev_item) - scroll_top + height < margin) {
top_item = entries[ entries.indexOf(prev_item) + 1];
} else if ( !down && (get_top_offset(prev_item) - scroll_top - height) > (margin + parent_from_top)) {
top_item = entries[ entries.indexOf(prev_item) - 1];
} else {
top_item = prev_item;
}
} else {
for (i = 0; entries[i]; i++) {
distance = get_top_offset(entries[i]) - scroll_top;
if ( distance < (parent_from_top + margin) && distance > (parent_from_top - margin) ) {
top_item = entries[i];
break;
}
}
}
 
if (top_item) {
if ( (down && top_item.getAttribute("data-8088-starter")) || ( !down && top_item.getAttribute("data-8088-ender") ) ) {
if (!anti_repeater) {
child = unscrollable[ entries.indexOf(top_item) ];
anti_repeater = child.cloneNode(false);
document.body.appendChild(anti_repeater);
child.style.visibility = "hidden";
style = anti_repeater.style;
style.position = 'fixed';
style.top = img_offset.top + 'px';
style.left= img_offset.left + 'px';
}
}
if ( (down && top_item.getAttribute("data-8088-ender")) || (!down && top_item.getAttribute("data-8088-starter")) ) {
unscrollable[ entries.indexOf(top_item) ].style.visibility = "visible";
if (anti_repeater) { anti_repeater.parentNode.removeChild(anti_repeater); }
anti_repeater = null;
}
}
prev_item = top_item;
//console.profileEnd();
}
}, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.