简体   繁体   English

完全加载Twitter小部件后调用函数

[英]Call a function after the Twitter widget has fully loaded

I'm having a bit of an issue at the moment with the Twitter API. 目前,Twitter API有点问题。 I have a sidebar which uses JavaScript to dynamically measure the height of the footer upon page load and page resize. 我有一个侧边栏,该边栏使用JavaScript在页面加载和页面调整大小时动态测量页脚的高度。

I've recently placed the Twitter widget into the footer, which is causing an issue where the Twitter widget always loads last, no matter where I place it within my JavaScript file. 我最近将Twitter小部件放置在页脚中,这会导致一个问题,即无论我将其放在JavaScript文件中的什么位置,Twitter小部件始终会最后加载。

I've tried to use the event handler for calling the measuring function after the Twitter widget has fully loaded, but it still doesn't make a difference. 我已经尝试在Twitter小部件完全加载后使用事件处理程序来调用Measurement函数,但是它仍然没有作用。

Does anyone have any suggestions? 有没有人有什么建议?

You have a few options to solve this problem. 您可以选择几种方法来解决此问题。 You could use a JS method such as .setInterval which would continue to loop until the Twitter widget is in the DOM and then execute your function. 您可以使用诸如.setInterval之类的JS方法,该方法将继续循环直到Twitter小部件位于DOM中,然后执行您的功能。 Or alternatively you could use setTimeout and force your update footer function to wait until the Twitter widget is present. 或者,您可以使用setTimeout并强制您的更新页脚函数等待,直到出现Twitter小部件。 I would recommend the former. 我会推荐前者。

If you're not comfortable using setInterval - you might want to check out this handy plugin that waits until your specified element is inserted into the DOM. 如果您不习惯使用setInterval-您可能想看看这个方便的插件,它会等待您将指定的元素插入DOM中。 Check it: https://gist.github.com/buu700/4200601 检查它: https : //gist.github.com/buu700/4200601

Asynchronous loading of third party widgets typically causes a few headaches. 第三方窗口小部件的异步加载通常会引起一些麻烦。 But the above solutions should point you in the right direction to sorting out your problem. 但是上述解决方案应该为您指出解决问题的正确方向。

Finally - do you know that the Twitter widget allows you to set a specified height in the Widget settings on your Twitter account? 最后-您知道Twitter小部件允许您在Twitter帐户的小部件设置中设置指定的高度吗? This might also solve your problem: https://dev.twitter.com/web/embedded-timelines#dimensions 这也可以解决您的问题: https : //dev.twitter.com/web/embedded-timelines#dimensions

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM