-
-
Save Cafnio/f897ffe29a0515d37483a8e4c40802eb to your computer and use it in GitHub Desktop.
Wordpress fixed widget bar with Jquery
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
jQuery( document ).ready(function() { | |
var fixmeTop = 100; // get initial position of the element | |
jQuery(window).scroll(function() { // assign scroll event listener | |
var distanceBottom = jQuery(document).height() - (jQuery(document).scrollTop() + jQuery(window).height()); | |
var currentScroll = jQuery(window).scrollTop(); // get current position | |
if (currentScroll >= fixmeTop && distanceBottom > 540) { // apply position: fixed if you | |
jQuery('#secondary').css({ // scroll to that element or below it | |
position: 'fixed', | |
top: '110px' | |
}); | |
}else if(currentScroll >= fixmeTop && distanceBottom <= 540){ | |
jQuery('#secondary').css({ // scroll to that element or below it | |
position: 'absolute', | |
top: parseInt(jQuery('.entry-content').css('height')) - 600, | |
}); | |
} else { // apply position: static | |
jQuery('#secondary').css({ // if you scroll above it | |
position: 'absolute', | |
top: 'unset' | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment