Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created July 11, 2012 09:33
Show Gist options
  • Save deanhume/3089294 to your computer and use it in GitHub Desktop.
Save deanhume/3089294 to your computer and use it in GitHub Desktop.
Socialite Scroll Demo
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://raw.github.com/dbushell/Socialite/master/socialite.min.js"></script>
<script>
// Only use jQuery if your website
$(document).ready(function () {
function CheckForDisplay() {
var element = document.getElementById("socialButtons");
if (elementInViewport(element)) {
Socialite.load();
}
}
function elementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= window.innerHeight &&
rect.right <= window.innerWidth
);
}
$(window).on('resize', CheckForDisplay).on('scroll', CheckForDisplay);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment