角JS - $ anchorScroll光滑/持续时间 [英] Angular js - $anchorScroll smooth/duration
问题描述
喜读角的js 文档我不知道,如果$ anchorScroll能有一个持续时间/宽松选项平滑滚动到的元素。
Hi reading the Angular Js doc i have no idea if $anchorScroll can have a duration/easing option to smooth scroll to elements.
它只是说:
$location.hash('bottom');
// call $anchorScroll()
$anchorScroll();
由于我不使用jQuery和我其实不希望,有一个聪明的,简单的方法,使或延长 $ anchorScroll
滚动更流畅的?
Since i do not use jquery and actually i don't want to, is there a clever, simple way to make or extend $anchorScroll
for scrolling more smooth ?
感谢
推荐答案
不幸的使用是不可能的 $ anchorScroll
。当你发现了 $ anchorScroll
没有任何选项,不与 $ ngAnimate
工作。为了动画滚动,你将需要使用自己的服务/工厂或只是直接的JavaScript。
Unfortunately this is not possible using $anchorScroll
. As you discovered $anchorScroll
doesn't have any options and doesn't work with $ngAnimate
. In order to animate the scroll you would need to use your own service/factory or just straight javascript.
有关自主学习的缘故,我放在一起的例子具有平滑滚动的服务。可能有更好的方法来做到这一点,因此任何反馈鼓励。
For the sake of self-learning I put together an example with a smooth scrolling service. There are probably better ways to do this so any feedback is encouraged.
要滚动到您附加了 NG-点击=元素gotoElement(ID)
的任何元素。我想一个更好的途径是使这个指令。
To scroll to an element you attach a ng-click="gotoElement(ID)"
to any element. I think an even better route would be to make this a directive.
下面是对的jsfiddle 的工作的例子。
Here's the working example on jsFiddle.
更新
现在有一些第三方的指令完成这个的。
There are now a number of third-party directives for accomplishing this.
- https://github.com/d-oliveros/ngSmoothScroll
- https://github.com/arnaudbreton/angular-smoothscroll
- https://gist.github.com/justinmc/d72f38339e0c654437a2
这篇关于角JS - $ anchorScroll光滑/持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!