Smooth scroll angular2

前端 未结 9 2196
旧巷少年郎
旧巷少年郎 2020-12-24 07:47

I am having trouble getting a smooth scroll service to work in angular 2. Are there any services for smooth scrolling, or plain anchor scrolling, that might work until the

9条回答
  •  借酒劲吻你
    2020-12-24 08:03

    there is a method in the window object called scrollTo(). If you set the behavior to 'smooth' the page will handle the smooth scroll. example (scroll to top of page):

     window.scrollTo({ left: 0, top: 0, behavior: 'smooth' });
    

    And with fallback example:

        try 
        { 
         window.scrollTo({ left: 0, top: 0, behavior: 'smooth' });
         } catch (e) {
          window.scrollTo(0, 0);
          }
    

提交回复
热议问题