I have a "fixed" menu bar on the left side of a website that I want to follow the scrollbar down the page when the user scrolls. I've tried two approaches so far, one css, and one jquery:
1) My first attempt was to use css style fixing:
#leftframe {
position:fixed;
width: 200;
}
Normally, this works great on vertical scrolling. The problem with this solution is that when the window isn't very wide, and the user tries to scroll, it goes right over the page contents.
2) After some research, I found that there's a jquery approach that allows you to fix an element in one direction, as described on stack overflow here: CSS: fixed position on x-axis but not y?
Using the approach outlined there, I wrote this nice little function to do it for me:
function float_vertical_scroll(id) {
$(window).scroll(function(){
$(id).css({
'top': $(this).scrollTop() //Use it later
});
});
}
Only, now the problem is, I've tried this in Chrome and Safari, and both show a noticeable flicker of the menu bar during vertical scrolling. The menu moves in a very "choppy" fashion, where the css solution smoothly slid it down the page.
Does anyone know why the jquery solution is so choppy, and if anything can be done about it? Is there some third solution that will give me the "best of both worlds"?
Thanks everyone.