我创建了一个 jquery 插件,它在左侧放置了一个用于社交媒体内容的侧边栏。我有下面的变量,这是内容的来源。我正在尝试使用小部件拉入 Twitter 提要,但我不断收到错误“TWTR 未定义”。有什么解决办法吗?
此页面正在调用我创建的插件 http://social.allthingswebdesign.com
var content = (
'<div class="contentArea visible" id="fb">FB Content Area</div>'+
'<div class="contentArea" id="twit"><script src="http://widgets.twimg.com/j/2/widget.js"></script><script>new TWTR.Widget({version: 2,type: \'profile\',rpp: 4,interval: 6000,width: 250,height: 280,theme: {shell: {background: \'#333333\',color: \'#ffffff\'},tweets: {background: \'#ffffff\',color: \'#444444\',links: \'#e02046\'}},features: {scrollbar: false,loop: false,live: false,hashtags: true,timestamp: true,avatars: false,behavior: \'all\'}}).render().setUser(\'CSuitesIndepend\').start();</script></div>'+
'<div class="contentArea" id="youtube">Youtube Video</div>'+
'<div class="contentArea" id="yelp">Yelp reviews</div>'+
'<div class="contentArea" id="ta">Trip Advisor Advice</div>'+
'<div class="contentArea" id="li">The Linked In Page</div>'
);
此外 - 如果我删除此行 <script src="http://widgets.twimg.com/j/2/widget.js"></script>
从插件中,并将其放在我的网页的头部,我只看到 Twitter 提要。
编辑: 好吧,现在我在想,为什么我不能只附加 Twitter 小部件代码 - <script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 4,
interval: 6000,
width: 250,
height: 280,
theme: {
shell: {
background: '#333333',
color: '#ffffff'
},
tweets: {
background: '#ffffff',
color: '#444444',
links: '#e02046'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
hashtags: true,
timestamp: true,
avatars: false,
behavior: 'all'
}
}).render().setUser('CSuitesIndepend').start();
</script>
- 通过插件动态插入的元素?
当我尝试这段代码时,它不会将任何内容插入#tweetFeed -
$(document).ready(function() {
// add the sidebar plugin
$('html').social(function() {
//console.log('#tweetFeed = '+ $('#tweetFeed').parent().html());
$('#tweetFeed').insertAfter("<p>TEST</p>");
});
//console.log('#tweetFeed = '+ $('#tweetFeed').parent().html());
$('#tweetFeed').insertAfter("<p>TEST</p>");
});
最佳答案
有一个未记录的功能允许您定位要在其中加载小部件的元素的 ID。 我能够使用 $.getScript 以及 twitter 提供的普通小部件代码来加载它来代替选择。
这是我使用的脚本,希望对您有所帮助...
$(document).ready(function(){ $.getScript('http://widgets.twimg.com/j/2/widget.js', function () { new TWTR.Widget({ version: 2, type: 'profile', id : 'twitterBox', rpp: 4, interval: 30000, width: 'auto', height: 'auto', theme: { shell: { background: 'transparent', //this is important color: '#333' }, tweets: { background: 'transparent', //this is important color: '#666', links: '#d14836' } }, features: { scrollbar: false, loop: false, live: false, behavior: 'all' } }).render().setUser('username').start(); }); });
关于javascript - 需要有关 Twitter 小部件的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6754251/