goddamnyouryan
goddamnyouryan

Reputation: 6906

div that sticks to the top when you scroll past it in jquery

For example...the new facebook activity stream on the right. Or on okay cupid (the message/rating dialogue).

How does this work exactly. Can someone point me to a tutorial or explanation?

Thanks!

Upvotes: 0

Views: 176

Answers (2)

golf
golf

Reputation: 354

Add some Javascript to set position: fixed; top: 0px; when $(window).scrollTop() reaches the $("#element_id").offset().top.

Google does a similar thing with their new gmail look

Upvotes: 2

John Hartsock
John Hartsock

Reputation: 86892

There are many ways to do this but here is one using CSS only

<div style="position:fixed; left:0; top:0; height:100px; width:100%">Stuck to Top</div>

Here is a fiddle

http://jsfiddle.net/2kmQe/

Upvotes: 4

Related Questions