scrolltop with animate not working

后端 未结 6 817
梦毁少年i
梦毁少年i 2020-12-01 11:53

I\'m trying to animate while scrolling but no luck with my code...

I have this jquery

$(window).scrollTop(200);

Now wanted to give

6条回答
  •  攒了一身酷
    2020-12-01 12:32

    I'm using Angular and was trying to scroll down to an item that had been added in an ng-repeat. I put this code inside a $timeout (with zero time, just to make it happen after the elements displayed) and this was sufficient for the new item to have an offset().top...

    ...but I think there was just way too much going on adding dozens of new elements, so it didn't have the processing power to scroll-animate. When I set the timeout time to 1 second, it worked (though it actually took 7 seconds before the timeout got called).

    I concluded that animated, smooth scrolling won't really be tractable here, and instead I'm just using

    document.body.scrollTop = entry.offset().top
    

提交回复
热议问题