Skip to content

Instantly share code, notes, and snippets.

@tarnfeld
Created October 3, 2011 00:36
Show Gist options
  • Select an option

  • Save tarnfeld/1258176 to your computer and use it in GitHub Desktop.

Select an option

Save tarnfeld/1258176 to your computer and use it in GitHub Desktop.
//## SCROLL ##//
function sTo(sel){
var v = 0;
if (sel.index() == 0) v = - 31;
$('#full').animate({scrollTop: sel.offset().top - v},'slow');
}
var start = $('.set[data-hash="' + window.location.hash + '"]');
if (start.length > 0) {
sTo(start);
}
$('#full').scroll(function() {
var el = false,
_this = $(this),
scroll = $(this).scrollTop();
$('.set').each(function(i, e) {
var v = 0;
if (i == 0) v = $(_this).position().top;
var top = $(e).offset().top + $(_this).scrollTop() - v,
bottom = top + $(e).outerHeight(true);
if (!el && scroll >= top && scroll <= bottom) {
el = $(this);
}
});
if (el) window.location.hash = $(el).data('hash');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment