简体   繁体   English

如何使用角度滚动scrollToElement?

[英]How to scrollToElement using angular-scroll?

I'm using Angular Scroll and once you hit a certain page I fire a function to scroll to an id. 我正在使用Angular Scroll ,一旦您点击了某个页面,我就会启动一个函数来滚动到一个id。 I'm getting the following error on the code below: 我在下面的代码上收到以下错误:

TypeError: $document.scrollToElement is not a function TypeError:$ document.scrollToElement不是函数

initHelp();

function initHelp() {
    console.log('initHelp');
    $document.scrollToElement('#chart-help', 500).then(function() {
        console && console.log('You just scrolled to chart-help!');
    });
}

The docs from angular-scroll 来自angular-scroll的文档

.scrollTo( element [, offset, [, duration [, easing ] ] ] )

Alias of .scrollToElement.

.scrollToElement( element [, offset, [, duration [, easing ] ] ] )

Figured it out: 弄清楚了:

var chartHelp = angular.element(document.getElementById('chart-help'));

$document.scrollToElement(chartHelp, 30, 500).then(function() {
    console && console.log('You just scrolled to chart-help!');
});

Also from their docs, I was missing the offset number: $document.scrollToElement(someElement, offset, duration); 同样在他们的文档中,我缺少偏移号: $document.scrollToElement(someElement, offset, duration);

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

相关问题 角度滚动不起作用...缺少某些东西吗? - angular-scroll not working…something missing? 如何使用scrollToElement转到新页面并滚动到特定的div - How to go to new page and scroll to a particular div using scrollToElement Angular-Scroll:与示例相同,但不起作用(柱塞) - Angular-Scroll: same as example, but not working (Plunker) Angular scrollToAnchor 在元素列表中无法正常工作 /common.js scrollToElement 为每个元素使用相同的滚动位置 - Angular scrollToAnchor not working properly in a list of elements /common.js scrollToElement is using the same scroll position for each element 在iOs phonegap应用程序上使用scrolltoelement不会滚动iAnim - iScroll no animation using scrolltoelement on iOs phonegap app 如何使用角度js滚动div的底部 - how to scroll bottom of div using angular js 如何滚动到 Angular 中的组件? - How to scroll to a component in Angular? 如何使用Angular Material表滚动到特定页面中的特定行 - How to scroll to a specific row in a specific page using Angular Material table 如何使用 CdkScrollable 检测角度材料 2 自动完成列表上的滚动事件 - How to detect scroll event on angular material 2 autocomplete list using CdkScrollable 使用角度的页面滚动事件 - Page Scroll Event using angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM