页面上的所有推特推文都呈现了事件/回调

All Twitter tweets on page rendered event/callback

本文关键字:事件 回调      更新时间:2023-09-26

我正在处理这段代码。

twttr.ready(function (twttr) {
    // At this point the widget.js file had been loaded.
    // We can now make use of the twttr events
    twttr.events.bind('rendered', function (event) {
         // At this point the tweet as been fully loaded
         // and rendered and you we can proceed with our Javascript
        console.log("Created widget", event.target.id);
    });
});

不幸的是,"rendered"事件将为每条推文分别触发,当页面上的所有嵌入推文都被渲染/显示时,是否有适当的方式来得到通知?

好的,我找到了合适的解决方案。您需要监听"loaded"事件,该事件只有在所有推特宽度显示后才会触发。

twttr.ready(function (twttr) {
    // At this point the widget.js file had been loaded.
    // We can now make use of the twttr events
    twttr.events.bind('loaded', function (event) {
         // At this point all tweets have been fully loaded
         // and rendered and you we can proceed with our Javascript
        console.log("Created widget", event.target.id);
    });
});