I have a menu that floats in a window when scrolling. Currently, my menu always remains at 190px at the top of the window. I am using a dimension plugin and here is my jQuery:
$(document).ready(function() { menuYloc = parseInt($('#mainMenu').css('top').substring(0,$('#mainMenu').css('top').indexOf('px'))) $(window).scroll(function () { var offset = menuYloc+$(document).scrollTop()+'px'; $('#mainMenu').animate({top:offset},{duration:600,queue:false}); }); });
What I would like to do is that when you scroll to the top of the page, the menu is 190 pixels from the top. However, when you start scrolling through the menu, the page scrolls until it reaches 50 pixels at the top of the window, then it starts to float, always staying 50 pixels from the top of the window, unless you scroll back to the top of the window .
Hope this makes sense and please let me know if you have a solution.
source share