Skip to content

Instantly share code, notes, and snippets.

@antenando
Created March 20, 2017 20:08
Show Gist options
  • Select an option

  • Save antenando/e9d691bb983b09a8b1b7743b1d8a83b0 to your computer and use it in GitHub Desktop.

Select an option

Save antenando/e9d691bb983b09a8b1b7743b1d8a83b0 to your computer and use it in GitHub Desktop.
var StickyFooter = (function ($) {
var $body = $('html, body');
var $footer = $body.find('.main-footer');
var $CTAfooter = $body.find('.cta-footer');
function init() {
if ($footer.length && $CTAfooter.length) {
checkFooter();
triggerEventScrolling(checkFooter);
}
}
function checkFooter(){
// by anteNando
// using https://github.com/customd/jquery-visible
// important thing here is to keep observing a static element (.main-footer) and set the fixed one (.cta-footer)
// when the static is visible
if (!isVisible($footer, true)) $CTAfooter.addClass('is-fixed');
if (isVisible($footer, true)) {
$CTAfooter.removeClass('is-fixed');
return;
}
$CTAfooter.addClass('is-fixed');
}
function triggerEventScrolling(callback) {
$(window).on('scroll', callback);
}
function isVisible(el, onViewport) {
return el.visible(onViewport);
}
function isFixed() {
return $CTAfooter.hasClass('is-fixed');
}
init();
return {
isFixed: isFixed
}
})($);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment