ScrollTo function in AngularJS

后端 未结 9 1889
梦如初夏
梦如初夏 2020-11-27 11:43

I\'m trying to get a quick nav to work correctly. It\'s floating on the side. When they click on a link, it takes them to that ID on the page. I\'m following this guide fro

9条回答
  •  时光说笑
    2020-11-27 12:09

    Another suggestion. One directive with selector.

    HTML:

    
    

    Angular:

    app.directive('scrollTo', function () {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                element.on('click', function () {
    
                    var target = $(attrs.scrollTo);
                    if (target.length > 0) {
                        $('html, body').animate({
                            scrollTop: target.offset().top
                        });
                    }
                });
            }
        }
    });
    

    Also notice $anchorScroll

提交回复
热议问题