简体   繁体   English

如何在 Angular-Material 主题中进行平滑滚动?

[英]How to do Smooth Scroll in Angular-Material theme?

I am starting a new project and using Angular Material with AngularJS.我正在开始一个新项目并在 AngularJS 中使用 Angular Material。 I am having trouble to make smooth scrolling work.我无法平滑滚动工作。 I am using this smooth scroll library: https://github.com/oblador/angular-scroll我正在使用这个平滑滚动库: https : //github.com/oblador/angular-scroll

I also try this one: https://github.com/d-oliveros/ngSmoothScroll But none of them work.我也尝试过这个: https : //github.com/d-oliveros/ngSmoothScroll但它们都不起作用。 I make a codepen to demo the problem here:我制作了一个代码笔来演示这里的问题:

http://codepen.io/hughred22/pen/XmRpOG/ http://codepen.io/hughred22/pen/XmRpOG/

As you see in my Codepen, if I comment out正如你在我的 Codepen 中看到的,如果我注释掉

document.getElementById('bottom').scrollIntoView(true);

To show scrollIntoView work and it scroll to the div.显示 scrollIntoView 工作并滚动到 div。 But smooth scroll won't work for some reason.但由于某种原因,平滑滚动不起作用。 Please help!请帮忙!

You should use the proper container to initiate scrolling.您应该使用正确的容器来启动滚动。 Check a fixed fork of your codepen here http://codepen.io/harconst/pen/qOmPVo在此处检查您的 codepen 的固定分支http://codepen.io/harconst/pen/qOmPVo

Notice that in my codepen, the container is not the whole document anymore.请注意,在我的 codepen 中,容器不再是整个文档。

var someElement = angular.element(document.getElementById('bottom'));
var container   = angular.element(document.getElementById('container'));    
container.scrollTo(someElement,0,1000);   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM