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 7
rgranlundAsked:
Who is Participating?
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?
0
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

0
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

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.
0
Marco GasiFreelancerCommented:
Glad to help you. Cheers
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.