0
延迟指令运行的最佳方式是什么?在指令执行之前需要等待的状态之间有一个小的延迟,否则会弄乱滚动。我试图使用$timeout
,但似乎可以用它错了,因为它会引发错误...延迟角度指令执行
app.directive('scrolltop', function() {
return {
restrict: 'A',
link: function(scope, element) {
element.on('click', function() {
console.log('scrolltop');
$('html, body').animate({
scrollTop: $(element).offset().top - 50
}, 2000);
});
},
}
});