Sticky sidebar
-
I found this code here https://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.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
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Sticky sidebar’ is closed to new replies.