我目前参与的任务是使用 wookmark 插件和 angularjs 创建类似 pinterest 的缩略图。因为服务器需要时间来响应,所以我能够使用 10 秒的 $timeout 显示缩略图。我想在数据完全加载后调用布局。我曾尝试过 promise 但没有运气。
有什么方法可以不使用 $timeout 来调用 Wookmark 布局吗?
我的代码如下:
myApp.controller("MyCtrl", ['$scope', '$timeout', 'eventData', function($scope, $timeout, eventData) {
function init() {
$scope.publicstreams = [];
$scope.publicstreams = eventData.getEvent(0);
$timeout(initWookmark, 10000);
}
function initWookmark() {
var options = {
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $('#tiles'), // Optional, used for some extra CSS styling
offset: 5, // Optional, the distance between grid items
flexibleWidth: 310 // Optional, the maximum width of a grid item
};
var handler = $('#tiles li');
$('#tiles').imagesLoaded(function() {
// Prepare layout options.
// Get a reference to your grid items.
// Call the layout function.
handler.wookmark(options);
});
handler.wookmark(options);
}
init();
}]);
如有任何帮助,我们将不胜感激!
最佳答案
感谢上帝!
最后我自己弄明白了。我在 $timeout 中将延迟设置为 0,它起作用了。
怎么做?
$timeout 实际上在 DOM 在浏览器中完成渲染后执行。所以即使是 0 毫秒的延迟也能起作用。
关于javascript - AngularJS - 在不使用 $timeout 的情况下调用书签布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17829666/