Forums
Forums / Plugins / Hacks / Sticky sidebar
(@makeupedia)
10 years, 9 months ago
I found this code here http://andrewhenderson.me/tutorial/jquery-sticky-sidebar/ and wanted to try it. Unfortunately I can’t make it work.
I understand my div must be renamed to .sticky, but I believe there is something with the jQuery that I don’t understand.
.sticky
Here’s my code I use in functions.php:
wp_enqueue_script("jQuery"); $(function(){ // document ready if (!!$('.sticky').offset()) { // make sure ".sticky" element exists var stickyTop = $('.sticky').offset().top; // returns number $(window).scroll(function(){ // scroll event var windowTop = $(window).scrollTop(); // returns number if (stickyTop < windowTop){ $('.sticky').css({ position: 'fixed', top: 0 }); } else { $('.sticky').css('position','static'); } }); } });
Help very much appreciated /Ca
(@leejosepho)
Maybe study this plugin a bit to see how its author does things: https://wordpress.org/plugins/standard-widget-extensions/
The topic ‘Sticky sidebar’ is closed to new replies.