Sticking div to top when scrolling flickering if a specific height is set
===

I have a div which turn to position:fixed when it reach a specific position (and stick to the top of the window). It works well but when I add some elements in the page which change the size of the body if this size is the height of the browser window the scroll will flick and I can't reach the bottom of the page BUT if the height of the body is more than the height of the window everything works.

here's the js :

    $(function()
    {
    	if ($('ul#add_custom_content').length)
    	{
    		var standardPosition = $('ul#add_custom_content').offset().top;
    		
    		$(window).scroll(function() {
    		    if ($(this).scrollTop() >= standardPosition) $('ul#add_custom_content').addClass('fixed');
    		    else $('ul#add_custom_content').removeClass('fixed');
    		});
    	}
    });

Any help will be very appreciated! Thanks!