2011-09-23 19 views
1

這裏是我的代碼,自動刷新含有鳴叫一個div來自Twitter拉:如何使用JQuery .live()而無需任何人爲交互,即點擊等?

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(); 

所以實際上我拉tweets並推動他們進入一個字幕和初始化Remy Shap rp的marquee插件,因爲div正在刷新我認爲marquee插件沒有初始化後inital刷新,因爲經過第一次刷新完美的作品,螢火蟲報道:

marqueeState is undefined

我看着使用.live()但不知道用什麼事件類型,因爲我無法想象一個不要求用戶交互。

有什麼想法?

回答

1

我會用livequery插件,做這樣的事情:

$('div.twitter marquee').livequery(function() { 
    $(this).marquee(); 
}); 

或者你可以使用custom events用.live()。

1

嘗試使用的window.onload = functionName

相關問題