Can you help me understand how to create a scrolling element that follows the scrolling of the window?
I want the element to scroll down when the window reaches the end, and scroll up when the window is at the top.
I tried implementing this functionality but couldn't figure it out.
Below is the code I attempted to use:
$(window).on('scroll',function(event) {
var lengthScrollWindow = $(this)[0].scrollTop;
if ($(this).scrollTop() == 0) {
lengthScrollWindow -= 40;
$('.main_profile').animate({scrollTop: lengthScrollWindow},700);
}
else if ($(this).scrollTop() >= $(this)[0].scrollHeight) {
lengthScrollWindow += 40;
$('.main_profile').animate({scrollTop: lengthScrollWindow},700);
}
});
Here is the link to my Fiddle for reference: