Created
June 23, 2016 02:53
-
-
Save khoipro/818911783a9c821a3e1ca69ec224182e to your computer and use it in GitHub Desktop.
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
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