jQuery Cycle& jTweets在一起的任何地方

时间:2012-03-03 02:08:36

标签: jquery cycle

我想使用jTweetsAnywhere来显示我的最新推文,然后我想使用jQuery Cycle逐个浏览推文。问题似乎是jTweetsAnywhere的标记需要在jQuery Cycle加载或jQuery Cycle不能工作之前加载。

jTweetsAnywhere:

$(document).ready(function () {
    $('#latest-tweets').jTweetsAnywhere({
        username: 'Twittername',
        count: 5,
    });
});

jQuery循环:

$(window).load(function() {
    $('#latest-tweets ul').cycle({
        fx: "scrollDown",
        easing: "easeOutCubic",
        speed: 600,
        timeout: 5000
    });
});

如何在jQuery循环之前获取要加载的推文标记?

3 个答案:

答案 0 :(得分:0)

您需要查看您的插件是否有完成回调并从那里开始幻灯片。检查插件文档/ API

答案 1 :(得分:0)

如果没有回调,您可以尝试使用timer检查是否已加载推文标记,然后初始化jQuery Cycle

<强>伪代码

var intervalID; 
intervalID = setInterval(initJQueryCyle, 500); // Half second
function initJQueryCycle(){
  // Check DOM here
  if ($('#latest-tweets li').length === 5)
  {
    // Stop timer
    clearInterval(intervalID);

    // initialiseJQueryCycle here
    $('#latest-tweets ul').cycle(options);        
  }
}

答案 2 :(得分:0)

刚刚将更新推送到jTweetsAnywhere github repo。该插件现在支持两个新的事件处理程序,这些事件处理程序在填充tweet提要时被调用。

onReadyHandler 在最初加载推文后只调用一次 并添加到DOM。在调用此事件处理程序之后立即执行 调用onFeedPopulationHandler并将invocations参数设置为 0

每次添加新推文时都会调用 onFeedPopulationHandler 到推文提要 - 从而到DOM。提供的事件处理程序 应该有以下接口:function(invocations,options){} invocations参数包含当前的#调用 处理程序,从第一次调用的0开始。调用此事件处理程序 通过分页或自动刷新来填充Feed。

样品:

$(document).ready(function()
{
    $('#jta_testfeed').jTweetsAnywhere(
    {
        searchParams: 'q=html5',
        count: 5,

        parts: ['connect-button', 'login-info', 'tweet-box', 'tweets'],

        showTweetFeed:
        {
            autoConformToTwitterStyleguide: true,
            showProfileImages: true,

            paging:
            {
                mode: 'more'
            },
            autorefresh: 
            {
                mode: 'trigger-insert',
                interval: 30
            },
            showTimestamp:
            {
                refreshInterval: 10
            }
        },
        onReadyHandler: function()
        {
            if (console)
            {
                console.log('onReadyHandler: # of children = ' + $('.jta-tweet-list').children().length);
            }
        },
        onFeedPopulationHandler: function(invocations)
        {
            if (console)
            {
                console.log('onFeedPopulationHandler: invocations: ' + invocations + ', # of children = ' + $('.jta-tweet-list').children().length);
            }
        }
    });
});