It is quite funny, but factually many a times we can do far better, more customized works without any plugin. WordPress Sticky Floating Widget or Menu Without Plugin is Possible to Deploy via jQuery or CSS. We Can Logically Use that for Post Pages. Q2W3 Fixed Widget is a well known WordPress Plugin which is easy if you fear minimal coding. We will give an approximate example, you need to customize it for your own design.
Why We Need WordPress Sticky Floating Widget or Menu Without Plugin?
Sidebar is a crucial aspect for a professional look. When the reader scrolls down a longer post page, the sidebar ends and that space remains empty. None can write similar sized posts. Websites with wordPress sticky floating widget or menu, one sidebar widget will stick and float along with the scrolling down of the longer post page. This is useful for you to get more attention to one of your sidebar widget. 5 years ago, we wrote what to put on a sidebar, that is not exactly the topic we are discussing in this guide. You may read later.
It does not need explanation – using more plugins is more bad.
---
WordPress Sticky Floating Widget or Menu Without Plugin : Via CSS or JS
We can inject an inline CSS or Js with Header and Footer plugin or Genesis Plugin for Genesis Theme Framework. The working principle is same as we used in Drop Caps without Plugin. jQuery loads in normal WordPress front-end. So, it is just easy to use jQuery plugin. Hartley wrote a great way, which you may read for full technical details :
1 | https://blog.hartleybrody.com/creating-sticky-sidebar-widgets-that-scrolls-with-you/ |
What he did is an easy trick, if you wrap with catcher
and sticky
div class,
1 2 3 4 5 6 7 | <div id="catcher"> <!--stuffs here--> </div> <div id="sticky"> <!--more stuffs here--> </div> |
and add this jQuery written by him (and customize after reading his detailed guide), it is just easy :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <script> $(document).ready(function() { function isScrolledTo(elem) { var docViewTop = $(window).scrollTop(); //num of pixels hidden above current screen var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top; //num of pixels above the elem var elemBottom = elemTop + $(elem).height(); return ((elemTop <= docViewTop)); } var catcher = $('#catcher'); var sticky = $('#sticky'); $(window).scroll(function() { if(isScrolledTo(sticky)) { sticky.css('position','fixed'); sticky.css('top','0px'); } var stopHeight = catcher.offset().top + catcher.height(); if ( stopHeight > sticky.offset().top) { sticky.css('position','absolute'); sticky.css('top',stopHeight); } }); }); </script> |
WP Enqueue Script can be used to inject the javascript and put it to footer.
Funnily, it is more easier with CSS. With CSS position:fixed
, we can easily active the same result in more easy way. If you wrap a div with :
1 2 3 | <div id="sticky"> <!-- stuffs here--> </div> |
and adjust the parameters, you can easily get that fun :
1 | .sticky { position: fixed; top: 30px; width: 292px; } |