How to make div follow scrolling smoothly with jQuery?

后端 未结 10 2351
我寻月下人不归
我寻月下人不归 2020-11-28 19:24

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

10条回答
  •  無奈伤痛
    2020-11-28 19:53

    I needed the div to stop when it reach a certain object, so i did it like this:

    var el = $('#followdeal');
        var elpos_original = el.offset().top;
        $(window).scroll(function(){
            var elpos = el.offset().top;
            var windowpos = $(window).scrollTop();
            var finaldestination = windowpos;
            var stophere = ( $('#filtering').offset().top ) - 170;
            if(windowpos=stophere) {
                finaldestination = elpos_original;
                el.stop().animate({'top':10});
            } else {
                el.stop().animate({'top':finaldestination-elpos_original+10},500);
            }
        });
    

提交回复
热议问题