【发布时间】:2016-04-25 15:14:55
【问题描述】:
我只是一个初学者,所以不要评判我。
我见过很多 angularjs 插件(指令/服务)在没有任何时间(或时间 = 1ms)的情况下使用 $timeout 函数。
例如:
scope.openGallery = function (i) {
if (typeof i !== undefined) {
scope.index = i;
showImage(scope.index);
}
scope.opened = true;
document.body.style.overflow = 'hidden';
/////*******Here*******/////
$timeout(function() {
var calculatedWidth = calculateThumbsWidth();
scope.thumbs_width = calculatedWidth.width;
$thumbnails.css({ width: calculatedWidth.width + 'px' });
$thumbwrapper.css({ width: calculatedWidth.visible_width + 'px' });
smartScroll(scope.index);
});
};
他们这样做的任何具体原因或这样做的好处?
【问题讨论】:
标签: javascript angularjs