无限滚动手动触发器

时间:2012-05-26 00:10:55

标签: jquery wordpress triggers infinite-scroll

似乎没有工作... :-(看到更多关于它的投诉,但我找不到答案。

问题: 无限滚动有效但不是手动触发。 当我点击链接时,没有任何反应。 Firebug给出了

Infinite Scroll

我的代码:

    <?php echo ('<ul id="infinite">'); ?>
<?php 
$wp_query = new WP_Query();
$wp_query->query('paged='.$paged.'&cat=5&showposts=3&meta_key=video_video&orderby=meta_value&order=ASC'  . $post->ID);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php if ( get_post_meta($post->ID, 'video_video', true) ) : ?>
    <li class="video"><?php $home = array("h" => 290, "w" => 380, "zc" => 1, "q" =>100);
            //echo get('video_video');
            echo ('With: ');
            echo get('participant_first_name');
            echo ('&nbsp;');
            echo get('participant_last_name');
            echo ('</li>');?>

<?php endif;?>


<?php endwhile;?>

<?php if (get_post_meta($post->ID, 'video_video', true) ) { ?>
    <?php if ($wp_query->max_num_pages > 1) : ?>
        <nav id="nav-below" >
        <div id="next" >
        <?php next_posts_link( __( 'Scroll down for more', 'intowntheme' ) ); ?></div>
        </nav>
    <?php endif; //end nav ?>
<?php } else {  ?>
<p>There are no interviews at the moment </p>
<?php }   ?>     
</ul>     

我的剧本

jQuery('ul#infinite').infinitescroll({ 
    navSelector  : "#next",  // selector for the paged navigation (it will be hidden)
    nextSelector : "#next a",   // selector for the NEXT link (to page 2)
    itemSelector : "ul#infinite li",  // selector for all items you'll retrieve
    errorCallback: function() { 
          // fade out the error message after 2 seconds
          $('#infscr-loading').animate({opacity: 0.8},2000).fadeOut('normal');   
        },   
    loading         : {
         msgText: "<em>Loading the next year of Grantees...</em>",
        finishedMsg: "<em>You've reached the end of the Interviews.</em>"
    },
  });

  //kill scroll binding
    jQuery(window).unbind('.infscr');
    //setTimeout("jQuery('#next').slideDown();", 1000);
     //hook up the manual click guy.

    jQuery('#next a').click(function(){
        jQuery('#next a').infinitescroll('retrieve.infscr');
     return false;
    });

也尝试了

jQuery(document).trigger('retrieve.infscr');

而不是

jQuery('#next a').infinitescroll('retrieve.infscr');

但没有运气。

然后,Firebug说 trigger(retrieve.infscr) called incorrectly

3 个答案:

答案 0 :(得分:53)

Pfoe,发现它......万岁的好文档(不带这个插件!)

:此:

 jQuery('#next a').click(function(){
    jQuery('#next a').infinitescroll('retrieve.infscr');
 return false;
});

应该是:

jQuery('#next a').click(function(){
    jQuery('ul#infinite').infinitescroll('retrieve');
 return false;
});

最大的问题是.infscr不应该在那里.. 希望它可以帮助其他人..

类似文档的解决方案:

jQuery("#clickable_element").click(function(){
    jQuery('#main_content_container').infinitescroll('retrieve');
        return false;
});

注意:
如果您正在使用砖石或同位素,您可能必须添加manual trigger behavior才能使其正常工作。只需在infinitescroll之后加入manual-trigger.js,然后在调用插件时传递behavior: 'twitter'来传递行为。

答案 1 :(得分:1)

我做了以下调整以确保第一次点击后导航链接出现:

jQuery("#clickable_element").click(function(){
    jQuery('#main_content_container').infinitescroll('retrieve');
    jQuery('#pagination').show();
    return false;
});

答案 2 :(得分:0)

...也许 $('#next a')。click(); ?