Callback when all Template items finished rendering in Meteor?

前端 未结 7 994
-上瘾入骨i
-上瘾入骨i 2020-12-19 09:30

I\'m getting a collection of records and placing them in a Template, having them rendered {{#each}} and I want to display a loading icon until the last DOM node

7条回答
  •  一向
    一向 (楼主)
    2020-12-19 10:06

    You can use a jquery plugin like livequery to follow-up dom insertions for a specific selector:

    $('.my-rendered-element').livequery(function () {
        console.log('I've been added to the DOM');
    });
    

    If you also need to make sure images have been loaded and everything is well rendered you can use some other utility like this other plugin imagesLoaded, and do something like:

    $('.my-rendered-element').livequery(function () {
        $(this).imagesLoaded(function() {
            console.log('My images have been loaded');
        });
    });
    

    It's a workaround and it maybe doesn't integrate well with Meteor, but I found these 2 guys very useful in many situations.

提交回复
热议问题