Skip to content

Instantly share code, notes, and snippets.

@wibawasuyadnya
Last active July 26, 2022 02:44
Show Gist options
  • Save wibawasuyadnya/f901a9697b6f5f500f82d1bd7ef63a8f to your computer and use it in GitHub Desktop.
Save wibawasuyadnya/f901a9697b6f5f500f82d1bd7ef63a8f to your computer and use it in GitHub Desktop.
const element = document.querySelector('.bottomMenu');
const styleJs = {
display: 'none',
position: 'fixed',
opacity: '0.95',
left: '0',
bottom: '0',
width: '100%',
height: '120px',
zIndex: '1'
};
const getStyles = obj => Object.keys(obj).map(key => `${key}:${obj[key]}`).join(';');
//assign style to html from js
element.style.cssText = getStyles(styleJs);
jQuery(function($) {
var $win = $(window);
function ctaScrollUp() {
if ($win.scrollTop() > 100) {
$('.bottomMenu').fadeIn();
}
}
function ctaScrollDown() {
if ($win.scrollTop() < 100) {
$('.bottomMenu').fadeOut();
}
}
function ctaHide() {
if ($win.scrollTop() > 485) {
$('.bottomMenu').css( { position: 'relative', bottom: '0'});
}
}
function ctaShow() {
if ($win.scrollTop() < 485) {
$('.bottomMenu').css( { position: 'fixed', bottom: '0'});
}
}
$win.scroll(ctaScrollUp);
$win.scroll(ctaScrollDown);
$win.scroll(ctaHide);
$win.scroll(ctaShow);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment