Skip to content

Instantly share code, notes, and snippets.

@khoipro
Created June 23, 2016 02:53
Show Gist options
  • Save khoipro/818911783a9c821a3e1ca69ec224182e to your computer and use it in GitHub Desktop.
Save khoipro/818911783a9c821a3e1ca69ec224182e to your computer and use it in GitHub Desktop.
var $ = require( 'jquery' ),
throttle = require( 'modules/throttle' );
module.exports = function( el ) {
var $el = $( el ),
$window = $( window ),
$bar = $( '#bottom-bar' ),
$close = $bar.find('.close-icon'),
$footer = $( '.footer' );
// Add session to display once per session
if (sessionStorage.getItem('bottom-bar') !== 'true') {
// Show bottom bar
$window.on('scroll', throttle(function() {
var scroll = $(this).scrollTop();
// Condition: Begin scroll + hide when move to footer
if (scroll > 1 && scroll + $window.height() < $footer.offset().top ) {
$bar.removeClass('hide');
} else {
$bar.addClass('hide');
}
}, 50));
}
// Close bottom bar
$close.on( "click", function(e) {
e.preventDefault();
sessionStorage.setItem('bottom-bar', 'true');
$bar.remove();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment