Skip to content

Instantly share code, notes, and snippets.

@hartliddell
Created June 26, 2014 18:44
Show Gist options
  • Save hartliddell/f4835ce1f4dd9209d4f9 to your computer and use it in GitHub Desktop.
Save hartliddell/f4835ce1f4dd9209d4f9 to your computer and use it in GitHub Desktop.
// Initiate scrolling social menu on single blog posts
function initSocialScroll() {
if($('article').hasClass('single-blog')) {
setTimeout(function() {
var $hornav = $('#horizontal_nav');
var $socialWrap = $('.social-like-wrapper');
var $_article = $('.single-blog .entry-content');
var articleTop = $_article.offset().top;
var articleHeight = $_article.height();
if(articleHeight > 500) {
$(window).scroll(function() {
var navHeight = $hornav.height();
var _scroll = $(document).scrollTop();
// console.log(articleTop + '/' + articleHeight);
// console.log(_scroll);
if(_scroll - articleTop > navHeight*-1) {
if(_scroll - (articleHeight+articleTop-(navHeight+400)) > 0) {
$socialWrap.css({'position':'relative', 'top': (articleHeight-400) + 'px'});
} else {
$socialWrap.css({'position':'fixed', 'top': (navHeight+30) + 'px'});
}
} else {
$socialWrap.css({'position':'relative', 'top': '0'});
}
});
}
}, 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment