如何在没有任何人工交互(即单击等)的情况下使用 JQuery .live()?
这是我的代码,自动刷新包含从 twitter 中提取的推文的 div:
var twittercacheData;
var twitterdata = $('#bottom-bar').html();
var twitterauto_refresh = setInterval(
function ()
{
$.ajax({
url: 'twitter.php',
type: 'POST',
data: twitterdata,
dataType: 'html',
success: function(twitterdata) {
if (twitterdata !== twittercacheData){
//data has changed (or it's the first call), save new cache data and update div
twittercacheData = twitterdata;
$('#bottom-bar').fadeOut("slow").html(twitterdata).fadeIn("slow");
}
}
})
}, 60000); // check every minute - reasonable considering time it takes 5 tweets to scroll across
唯一的事情是在 twitter.php 中我这样做:
// initialise the marquee plugin so that we get a nice smooth scrolling effect
$('div.twitter marquee').marquee();
所以实际上我正在拉推文并将它们推入字幕并初始化 Remy Shap rp 的选框插件,因为 div 正在刷新,我认为选框插件在初始刷新后没有被初始化,因为在第一次刷新后,效果完美,firebug 报告:
marqueeState is undefined
我研究过使用 .live()
但不知道要使用什么事件类型,因为我想不出不需要用户交互的事件类型。
有什么想法吗?
Here is my code that auto refreshes a div containing tweets pulled from twitter:
var twittercacheData;
var twitterdata = $('#bottom-bar').html();
var twitterauto_refresh = setInterval(
function ()
{
$.ajax({
url: 'twitter.php',
type: 'POST',
data: twitterdata,
dataType: 'html',
success: function(twitterdata) {
if (twitterdata !== twittercacheData){
//data has changed (or it's the first call), save new cache data and update div
twittercacheData = twitterdata;
$('#bottom-bar').fadeOut("slow").html(twitterdata).fadeIn("slow");
}
}
})
}, 60000); // check every minute - reasonable considering time it takes 5 tweets to scroll across
The only thing is that in the twitter.php I do this:
// initialise the marquee plugin so that we get a nice smooth scrolling effect
$('div.twitter marquee').marquee();
So in effect I am pulling tweets and shoving them into a marquee and initialising Remy Shap
rp's marquee plug-in and because the div is being refreshed I am thinking the marquee plugin isn't being initialised after the inital refresh because after the first refresh which works perfectly, firebug reports that:
marqueeState is undefined
I looked into using .live()
but don't know what event type to use because I can't think of one that doesn't require user interaction.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用 livequery 插件并执行以下操作:
或者您可以使用 自定义事件 与 .live()。
I would use the livequery plugin and do something like this:
Or you can use custom events with .live().
尝试使用 window.onload = functionName
try using window.onload = functionName
如果您想要可以通过编程方式触发的自定义事件,jQuery 可以提供:
http://fuelyourcoding.com/jquery-custom-events-他们将摇滚你的世界/
If you want custom events that can be triggered programatically, jQuery delivers:
http://fuelyourcoding.com/jquery-custom-events-they-will-rock-your-world/