![](/img/trans.png)
[英]Twitter Profile Widget - load inside specific div & include javascript in footer
[英]twitter's profile widget include in a separate javascript file
我只是想将自定义twitter的配置文件小部件放在我的页面上,但我想将代码放在单独的javascript文件中。
所以,我不知道该怎么做。
我的意思是,我把它放在头标签上
<script type="text/javascript" src="http://widgets.twimg.com/j/2/widget.js"></script>
为小部件创建一个div,将其余代码放入另一个javascript
new TWTR.Widget(json_twitter_options).render().setUser('username').start();
但是,如何将结果“放入”该小部件中……我已经完全迷失了,谢谢。
对我来说,解决方案只是向您希望小部件呈现到其中的元素的options对象添加一个“ id”属性。 这样,您甚至可以使用require.js或在页面加载后加载脚本,并且仍将小部件呈现到所需的空间中。
顺便说一下,我没有找到此属性的任何文档。
例如:
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 4,
interval: 6000,
width: 135,
height: 700,
theme: {
shell: {
background: '#e5e5e5',
color: '#363F49'
},
tweets: {
background: '#e5e5e5',
color: '#000000',
links: '#06C'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
hashtags: true,
timestamp: true,
avatars: false,
behavior: 'all'
},
id: 'someDivId'
}).render().setUser('comster').start();
只需将整个代码放入一个新的javascript文件(将其命名为twitter.js之类的任何名称),然后将其链接到想要显示的位置即可,例如
<div id="twittercode">[js file link goes here]</div>
这整个块应该放入一个新的javascript文件中。
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 4,
interval: 6000,
width: 135,
height: 700,
theme: {
shell: {
background: '#e5e5e5',
color: '#363F49'
},
tweets: {
background: '#e5e5e5',
color: '#000000',
links: '#06C'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
hashtags: true,
timestamp: true,
avatars: false,
behavior: 'all'
}
}).render().setUser('USERNAME').start();
js文件不必位于小部件上方的头部
此代码有效,我已经对其进行了测试:
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 4,
interval: 6000,
width: 135,
height: 700,
theme: {
shell: {
background: '#e5e5e5',
color: '#363F49'
},
tweets: {
background: '#e5e5e5',
color: '#000000',
links: '#06C'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
hashtags: true,
timestamp: true,
avatars: false,
behavior: 'all'
}
}).render().setUser('USERNAME').start();
</script>
好的,看来我的问题不明白。
我做不到我想要的。 但是简化我的问题的方法是创建一个用于设置小部件的json对象。
我仍然想找到一种在正文标签内不使用脚本标签的方法
非常感谢观看者!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.