Floating a Q2W3 Fixed Widget in Divi

Written by Dan Mossop

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.

Supercharge Your Divi Widgets with Magic CTAs

Enhance your Divi site with WP Magic CTAs. While setting up custom floating widgets using the Q2W3 Fixed Widget plugin, complement your design with perfectly targeted calls to action. Our AI-driven plugin effortlessly creates engaging CTAs for each post, boosting interaction and conversions. Avail 50% off until Sept 5!

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

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 *.

We may earn a commission when you visit links on our website.