I'm currently working on implementing a sticky sidebar snippet using jQuery. However, I am facing an issue where the function within .scroll()
is only executing once instead of on every scroll event. Can anyone help me identify what I might be doing incorrectly?
var sticky = $('#sticky');
var staticSticky = $(sticky).offset().top;
$(window).scroll(moveEl(sticky, staticSticky));
function moveEl(element, staticElToTop){
if( $(window).scrollTop() >= staticElToTop ){
$(element).css('top', $(window).scrollTop() + 'px');
}
}
You can view my current attempt here: http://codepen.io/ExcellentSP/pen/GqZwVG
At this stage, the code provided is not fully operational. My primary objective is to resolve the scroll event functionality before moving forward with further development.