In my container there are sections/boxes, but the last one of these boxes should follow scrolling when none of the other boxes are visible.
So, when user sc
This is my final code .... (based on previous fixes, thank you big time for headstart, saved a lot of time experimenting). What bugged me was scrolling up, as well as scrolling down ... :)
it always makes me wonder how jquery can be elegant!!!
$(document).ready(function(){
//run once
var el=$('#scrolldiv');
var originalelpos=el.offset().top; // take it where it originally is on the page
//run on scroll
$(window).scroll(function(){
var el = $('#scrolldiv'); // important! (local)
var elpos = el.offset().top; // take current situation
var windowpos = $(window).scrollTop();
var finaldestination = windowpos+originalelpos;
el.stop().animate({'top':finaldestination},500);
});
});