
This trick is applicable to any widget or element that has an ID, regardless of its location on your blog. It will float there until its original location comes back when the page is scrolled back up. It is perfect for navigation bar, subscription box and social media sharing buttons.
See it in action, scroll down this post and keep your eyes on the top menu bar.
How to install
- Paste the following code above the </body> tag in your template. Or if you prefer not to touch the template, you can simply paste it in a HTML/Javascript (in Blogger) or a Text widget (in WordPress). If you choose this route, make sure you position this widget below (after) the widget that you want to make sticky.
- Get the ID of the widget or element you want to make sticky and enter it in line 6 (replacing "YOUR_WIDGET_ID"). For example let's say the widget ID is HTML9, then code line 6 would become:
- Preview before saving.
Styling
- Styling for the sticky widget while it's sticking can be applied in line 28.
- Background and box-shadow are optional. However you might want to keep the background (and replace the color to match your sidebar's). Most templates do not assign a background to widgets meaning you can see the content scrolling in the background.
0 Response to "How to Create a Floating/Sticky Widget into Your Blog"
Post a Comment