Floating a Q2W3 Fixed Widget in Divi

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.

This post may contain referral links which may earn a commission for this site

Divi Booster

Hundreds of new features for Divi
in one easy-to-use plugin

2 Comments

  1. where do I need to put this code?

    Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.