Last active
August 29, 2015 14:25
-
-
Save craigbutcher/4e5d1efe464c331fc27e to your computer and use it in GitHub Desktop.
javascript module for sticky sidebar
This file contains 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
// Sticky sidebar - JavaScript | |
'use strict'; | |
var fixedSidebar = { | |
init: function() { | |
// Set up the click handlers. | |
this.bindUIActions(); | |
}, | |
bindUIActions: function() { | |
$(window).scroll(function(){ | |
fixedSidebar.scrolling(); | |
fixedSidebar.topOfPage(); | |
}); | |
}, | |
scrolling : function() { | |
var setGlue = $('.sidebar').offset().top; | |
var windowTop = $(window).scrollTop(); | |
var topPadding = 15; | |
// var documentHeight = $(document).scrollTop() + $(window).height() > $(document).height() - 100; | |
// console.log(documentHeight); | |
// if (documentHeight) { | |
// $('.sidebar').addClass('glue-to-bottom'); | |
// } else if (setGlue < windowTop) { | |
// $('.sidebar').removeClass('glue-to-bottom'); | |
// } | |
if (windowTop > setGlue) { | |
$('.sidebar').addClass('glue'); | |
} else if (windowTop < setGlue) { | |
$('.sidebar').removeClass('glue'); | |
} | |
}, | |
topOfPage : function() { | |
if ($(document).scrollTop() == 0) { | |
$('.sidebar').removeClass('glue'); | |
} | |
} | |
} | |
$(document).ready(function() { | |
fixedSidebar.init(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment