mol*_*man 0 javascript twitter iframe jquery masonry
我正在尝试使用多个嵌入式推文的Masonry.但我遇到了彼此重叠的元素问题.
我试过的一种方法是使用imagesLoaded插件按照参考指南,但这没有工作,因为我不认为每条推文的iframe没有完全加载我认为.
我试图只在页面加载时调用砌体,但我仍然有重叠的推文问题.
$(window).bind("load", function() {
var $container = $('#panel');
$container.masonry({
columnWidth: 300,
itemSelector: '.elem'
});
});
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做,有没有办法在我将它发送到客户端之前如何弄清楚可嵌入的推文的高度,以便我可以将其设置为iframe的内联样式.这是从twitter API返回的JSON数据.
=============statuses/oembed============
{ cache_age: '3153600000',
url: 'https://twitter.com/Cristiano/statuses/477052670197653504',
height: null,
provider_url: 'https://twitter.com',
provider_name: 'Twitter',
author_name: 'Cristiano Ronaldo',
version: '1.0',
author_url: 'https://twitter.com/Cristiano',
type: 'rich',
html: '<blockquote class="twitter-tweet"><p>Insane first half against the aliens! <a href="https://twitter.com/FALCAO">@Falcao</a>, we'll show them how we play football! <a href="https://twitter.com/search?q=%23GALAXY11&src=hash">#GALAXY11</a> <a href="http://t.co/z0FzRHz6gG">http://t.co/z0FzRHz6gG</a> <a href="http://t.co/pGJ4F1AcO0">pic.twitter.com/pGJ4F1AcO0</a></p>— Cristiano Ronaldo (@Cristiano) <a href="https://twitter.com/Cristiano/statuses/477052670197653504">June 12, 2014</a></blockquote>\n<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>',
width: 550 }
Run Code Online (Sandbox Code Playgroud)
服务器端我使用带有express的node.js
window.twttr = function (d, s, id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return; js = d.createElement(s); js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function (f) { t._e.push(f) } });
}(document, 'script', 'twitter-wjs');
twttr.ready(function (twttr) {
twttr.events.bind('loaded', function (event) {
//DO A MASONRY RELAYOUT HERE
msnry.layout();
});
});
Run Code Online (Sandbox Code Playgroud)
到目前为止,这对我来说效果很好.
| 归档时间: |
|
| 查看次数: |
1929 次 |
| 最近记录: |