首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无限滚动-将jquery效果应用于所有滚动页面上的元素

无限滚动-将jquery效果应用于所有滚动页面上的元素
EN

Stack Overflow用户
提问于 2013-11-21 13:19:57
回答 1查看 2.9K关注 0票数 3

我使用的是无限ajax-滚动插件以及一个倒计时插件、一个悬停字幕插件和Metro (http://www.drewgreenwell.com/projects/metrojs)。

JQuery效果在第一个页面上工作得很好,但是它们没有应用到通过无限滚动插件加载的页面。

我知道我需要在Infinite初始化中使用onLoadItemsonRenderComplete,但是,我对JQuery语法没有那么好,我希望能在这方面提供任何帮助。

代码语言:javascript
复制
//code for countdown applied to every element
echo "<script type=\"text/javascript\">
    $(window).load(function(){
        $('#countdown_$id').countdown({until: new Date($year, $month - 1, $day, $hour, $minute, $secs)});
    });
</script>";
echo '<div class="defaultCountdown" id="countdown_'.$id.'"></div>';

//code that applied hover captions and infinite scroll
$(document).ready(function () {
    $('.hcaption').hcaptions({
        effect: "fade"
    });
    //animate tiles
    $(".live-tile").liveTile({pauseOnHover: true});

    // Infinite Ajax Scroll configuration
    jQuery.ias({
        container: '#main', // main container where data goes to append
        item: '.element', // single items
        pagination: '.paginate', // page navigation
        next: '.paginate a', // next page selector
        loader: '<img src="public/img/ajax-loader.gif"/>', // loading gif
        loaderDelay: 200,
        thresholdMargin: -600,
        noneleft: 'No more discounts', //Contains the message to be displayed when there are no more pages left to load
        triggerPageThreshold: '10', // show "load more" if scroll more than this to stop
        trigger: "",
        onLoadItems: function (newElements) {
            // hide new items while they are loading
            var $newElems = $(newElements).css({
                opacity: 0
            });
            // ensure that images load before adding to isotope layout
            $newElems.imagesLoaded(function () {
                // show elems now they're ready
                $newElems.animate({
                    opacity: 1
                });
                $container.isotope('insert', $newElems, true);
            });
            return true;
        }
    });
    //end infinite
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-30 00:38:16

初始化卷轴时,需要使用onLoadItems onRenderComplete,如下所示:

代码语言:javascript
复制
jQuery.ias({
    container: '#main', // main container where data goes to append
    item: '.element', // single items
    pagination: '.paginate', // page navigation
    next: '.paginate a', // next page selector
    loader: '<img src="public/img/ajax-loader.gif"/>', // loading gif
    loaderDelay: 200,
    thresholdMargin: -600,
    noneleft: 'No more discounts'
    triggerPageThreshold: '10',
    trigger: "",
    onLoadItems: function (newElements) {
        // hide new items while they are loading
        var $newElems = $(newElements).css({
            opacity: 0
        });
        // ensure that images load before adding to isotope layout
        $newElems.imagesLoaded(function () {
            // show elems now they're ready
            $newElems.animate({
                opacity: 1
            });
            $container.isotope('insert', $newElems, true);
        });
        setTimeout("$('.hcaption').hcaptions({effect: 'fade'})",1000);
        setTimeout('$(".live-tile, .flip-list").not(".exclude").liveTile()',1000);
        return true;
    }
});
//end infinite

演示

我也试过

代码语言:javascript
复制
onRenderComplete: function(items) {
    $('.hcaption').hcaptions({effect: "fade"});
    $(".live-tile, .flip-list").not(".exclude").liveTile();
}

而且效果很好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20122108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档