i’m working on a menu which opened with a floating button. I would like to open the menu from the position i’m in, so i can see the menu. the problem is i can’t use css position: fixed; because the menu is quite big and requires scrolling the page.
$("#exp_menu").click(function() {
$("#left_block").show();
$("#exp_menu_close").show();
$("#exp_menu").hide();
});
I’m assuming that the
#exp_menuelement is the “menu” that you are referring to.You can get the current scroll position in your click event handler and update the position of the
#left_blockelement as necessary. If you want to dock the#left_blockelement to the top of the viewport you can use this:This solution requires that the
#left_blockelement is absolutely positioned and its offset parent is thebodyelement.$(window).scrollTop()returns the scroll position of the current window: http://api.jquery.com/scrolltop/