[英]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.