How to create sticky left sidebar which sticks on scrolling

sticky

On scroll we call stickyMenu function,

We check sidemenu’s ele.offset().top, which means y coordinate on page where element starts.

And then we compare it with $(document).scrollTop(), if offset().top is less than scrollTop, then we have passed by sidemenu, so we add sticky class to make it fixed, otherwise we remove sticky class.

and then when we scrolled past links container and reaching footer, we add the diff of height of parent and scrolltop as top to stickyMenu to push it upwards.

Archive