AngularJS - $anchorScroll smooth/duration

后端 未结 7 1317
你的背包
你的背包 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:10

    None of the solutions here actually does what OP originally asked, that is, make $anchorScroll scrolling smoothly. Difference between smooth scrolling directives and $anchroScroll is that it uses/modifies $location.hash(), which may be desirable in some cases.

    Here is gist for simple module that replaces $anchorScroll scrolling with smooth scrolling. It uses https://github.com/oblador/angular-scroll library for the scrolling itself (replace it with something else if you want, it should be easy).

    https://gist.github.com/mdvorak/fc8b531d3e082f3fdaa9
    Note: It actually does not get $anchorScroll to scroll smoothly, but it replaces its handler for scrolling.

    Enable it simply by referencing mdvorakSmoothScroll module in your application.

提交回复
热议问题