AngularJS - $anchorScroll smooth/duration

后端 未结 7 1332
你的背包
你的背包 2020-12-04 07:52

Reading the AngularJS docs I haven\'t figured out if $anchorScroll can have a duration/easing option to smooth scroll to elements.

It only says:

7条回答
  •  醉酒成梦
    2020-12-04 08:11

    I am not aware of how to animate $anchorScroll . Here's how I do it in my projects:

    /* Scroll to top on each ui-router state change */
    $rootScope.$on('$stateChangeStart', function() {
     scrollToTop();
    });
    

    And the JS function:

    function scrollToTop() {
        if (typeof jQuery == 'undefined') {
            return window.scrollTo(0,0);
        } else {
            var body = $('html, body');
            body.animate({scrollTop:0}, '600', 'swing');
        }
        log("scrollToTop");
        return true;
    }
    

提交回复
热议问题