Ok, here is what you need to do. First of all, The shaking behaviour is totally normal looking to your code, because !!! when you scroll, the test if (window_top > div_top)
is based on old positions.
Before moving your arrow. when your arrow is under the footer, you set it the way that window_top == div_top
will be true for the next scroll. Next scroll, window_top == div_top
will be true, so you move your arrow... etc... Anyway, what you need to do is :
1 : save initial arrow top position in a global var
var initialH = $('#arrow').offset().top;
2 : distinct up scroll and down scroll
How can I determine the direction of a jQuery scroll event?
3 : while scrolls are down, just check for
if (window_top > div_top)
if true, then you can replace fixed
by absolute
and attach the arrow to the footer.
4 : if the scroll is up :
if arrow_top < ( arrow_initial_height + $(window).scrollTop() )
, you musn't do anything, else, set back the original top offset to your arrow, so it will takes back is original position. You will get rid of the shaking effect.
For the smooth scroll, I'm sure there is a ton of tutorials that explain how to do it.
working fiddle : http://jsfiddle.net/be2Ff/30/