The Q2W3 Fixed Widget (Sticky Widget) plugin allows you to mark individual widgets as sticky, meaning that when you scroll up the page they will stay in position on the screen, rather than scrolling out of sight with the rest of the content. A good use for the plugin is to create "floating" widgets which hover above the page content, for instance to have social share buttons visible at all times.
Unfortunately, in some themes (including the Divi Theme), setting float:left on the sticky widget will not move it into position on the sidebar. This is because the theme is made up of a number of other left-floated elements. These elements block the widget, effectively keeping it in position.
To work around this, we can use a bit of JavaScript (jQuery, actually) to move the widget into a new position within page. By placing it before the other components, we'll prevent them from blocking the widget's floating. Here is the jQuery to move a widget with id "text-4" to the start of the Divi Theme page content:
jQuery("#et-main-area").prepend(jQuery("#text-4"));
This frees the widget, but doesn't fully achieve the floating effect we want. So we need to add some CSS to make it look right:
#text-4 { width:200px !important; z-index:100; position:fixed; } #text-4_clone { width:1;height:1; }
The first line sets the widget width and fixes it above the other content. The second line is used to prevent a hidden object created by the plugin from breaking the page layout. Note that the id selector in the second row is made up of the widget id followed by "_clone".
Now the widget should float on the left of the page. We may still need to set the top margin in the Q2W3 Fixed Widget settings to make sure the widget is not covered up by the header bar.
where do I need to put this code?
Hi Glen, the first block of code is jQuery code, so can be added as described here:
https://divibooster.com/adding-javascript-and-jquery-to-the-divi-theme/
The second block is CSS, so can be added as per this post:
https://divibooster.com/adding-css-to-the-divi-theme/