1Blerk 1Blerk - 1 year ago 74
jQuery Question

How to halt a div after scrolling a bit using jquery

I want a div to be vertically fixed at a defined scrolllevel. I tried this:


<div id='something'>Something! </div>


#something {


if ($window.scrollTop() > 50){
$("#something").css({"top": ($(window).scrollTop()) -50 + "px"});

Here is a demo: http://jsfiddle.net/1Blerk/3jacz/4/
(#something should do the same as #headerMenu, but after some scrolling)

And i do not want to change position to be fixed!

I am not really familiar with JQuery, so i guess it is just some parantheses or a selector or...

Thanks in advance!

Answer Source

You forgot to wrap $(window) in parenthesis.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download