jQuery div fixed position of div when scrolling.

I'm not 100% sure how to articulate this.  I have a div on a page sidebar. it is underneath a menu. the div CLASS is .ad-container Some pages have a short menu list and other pages have a long menu list.  As you scroll down the page and the .ad-container reaches 100px from the top of the browser screen I want it to have a position of fixed so it is always in the same place as you scroll down.  Also, as you scroll back up, when it reaches its original position, the fixed position no longer applies.
LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgrafxCommented:
Not sure you could do that - easily anyway.
How about setting it to fixed 100px from the top of screen?
Because it seems like you are wanting it to move only 100px - right?
Marco GasiFreelancerCommented:
You can use jQuery to do it:

jQuery(document).ready(function ()
{
    $(window).scroll(function() {
        if ($(this).scrollTop() === 100) { // this refers to window
            $('.ad-container').css('position', 'fixed');
        }
        else
       {
            $('.ad-container').css('position', 'static');
       }
    });
});

Open in new window

rgranlundAuthor Commented:
When I scrolled down it did nothing.  Should I use a z-index?
I changed it to this:
$(function ()
		{
		    $(window).scroll(function() {
		        if ($(this).scrollTop() >= 1000) { // this refers to window
		            $('.app-group-finder').css('position', 'fixed');
		        }
		        else
		       {
		            $('.app-group-finder').css('position', 'static');
		       }
		    });
		});

Open in new window

However, it just disappears.  What I want it to do is when I scroll down the screen, if the top of the div touches the top of the browser window, i scrolls down the page with me as I scroll.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Marco GasiFreelancerCommented:
Maybe I have yet asked this in some other your question but have you a live link to share?
rgranlundAuthor Commented:
Marco GasiFreelancerCommented:
Please, see if this makes sense to you: http://jsfiddle.net/zu60j5rr/10/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
Thanks ! That is exactly what I need to know how to do.
Marco GasiFreelancerCommented:
Glad to help you. Cheers
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.