How to make an element slide with the viewport as it scrolls?

Tags: javascript,jquery,css,position

Problem :

I've Googled for this but must be using the wrong keywords.

Basically I want to use the effect that Magento and now Stack Overflow uses. That is, there is an element in a column, and when you scroll down, it sticks to the top of the viewport. And once scrolled up again, it goes back into the normal page flow.

This Ask A Question is a good page for example. Scroll down and watch the "How to Format" element come down (might need to make your viewport smaller if you have a large screen to see the effect).

I've noticed it is setting position: fixed in the CSS. The JavaScript however is obfuscated.

What's the easiest way to achieve this effect? Is there a jQuery plugin available?

Solution :

Here is an article that should help:

    CSS Howto..

    how to make table header freeze/fixed when scrolling in html/css?

    How to have the class=“selected” depending on what the current page/url is

    How to fade text out vertically, similar to Amazon's product descriptions

    How to Style Social Media Links Correctly

    How do you make a make a page's worth of empty space (with only a title) followed by a div in CSS?

    How to align multiple columns in bootstrap 3 carousel?

    CSS- how to give an object with scooped corners a border colour?

    How to stretch image in img tag larger than its natural size?

    How to use one popup box to display arbitrary number of information respectively?

    CSS3 Transitions in Stylus - how to degrade for IE9

    how to order CSS elements?

    How can I position an element in the middle of the window while using position: absolute?

    How to convert 6 digit color code to 3 digit quickly in css file?

    How to stick a background behind the navbar?

    Hide the element, but show for that place blank

    How to fix Image on top of text with css

    How do I display epub format book in pure HTML5/CSS/Jquery

    How to blur one side of the div using CSS

    How to wrap text in table cell at hyphen?

    How to avoid CSS selector applying to more than one level of descendants

    how to select the first element of each class with css

    How to change styling of a specific div onhover of another element when divs share an id

    How do you size an SWF object based on a Blueprint CSS span range?

    How to display background-image on entire site

    How to get a style property from a css class and set it to another css class?

    How to put a background video loop on a website HTML/CSS

    How to display heading and paragraph elements inline in css?

    How to remove a div with fade out effect in JavaScript?

    How to emulate Google greyed-out suggested text in input element?

    how to center an item when it's the only one in a multi-column layout