Last active
October 13, 2015 12:47
-
-
Save ebinnion/4197977 to your computer and use it in GitHub Desktop.
Floating and Docking Sharebar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($){ | |
// Let's get the position of our sharebar container(where we want it) | |
// Cache these DOM traversals | |
var container = $('.content'); | |
var containerOffset = container.offset().top; | |
var containerLeft = container.offset().left; | |
var containerBottom = containerOffset + container.height(); | |
var sharebar = $('.viralshare'); | |
var sharebarHeight = 432; | |
sharebar.css('position', 'fixed'); | |
sharebar.css('left', containerLeft - 70); | |
sharebar.css('top', containerOffset + 50); | |
$(window).resize(function() { | |
var container = $('.content'); | |
var containerOffset = container.offset().top; | |
var containerLeft = container.offset().left; | |
sharebar.css('position', 'fixed'); | |
sharebar.css('left', containerLeft - 70); | |
sharebar.css('top', containerOffset + 50); | |
}); | |
$(window).scroll(function(){ | |
var fromTop = $(window).scrollTop(); | |
var sharebarTop = sharebar.offset().top; | |
var sharebarBottom = sharebarTop + sharebarHeight; | |
if ( sharebarTop + sharebarHeight -200 >= containerBottom && sharebar.css('display') != 'none'){ | |
sharebar.hide('slow'); | |
} | |
else if (sharebarTop + sharebarHeight < containerBottom && sharebar.css('display') == 'none'){ | |
sharebar.show('slow'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment