detail-list.page.js 1.39 KB
/**
 * 星潮教室-明星专题列表
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/6/7
 */
let $ = require('yoho-jquery'),
    tip = require('js/plugin/tip'),
    loading = require('js/plugin/loading'),
    lazyLoad = require('yoho-jquery-lazyload');

let $detailList = $('.detail-list'),
    stopLoading = false,
    page = 1;

require('./list-common');

// 翻页
function massageAJAX(pageData) {
    loading.showLoadingMask();
    $.ajax({
        type: 'GET',
        url: '/guang/star/detailList',
        data: {
            page: pageData,
            tag: $('.detail-list').data('name')
        },
        dataType: 'html',
        success: function(data) {
            stopLoading = false;

            if (data === '') {
                stopLoading = true;
                tip.show('没有更多内容了');
            }

            $('.detail-list').append(data);
            lazyLoad($('img.lazy'));
            loading.hideLoadingMask();
        },
        error: function() {
            tip.show('网络断开连接了~');
        }
    });
}

function scrollHandler() {
    if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() - 100)) {
        stopLoading = true;
        page++;
        massageAJAX(page);
    }
}

$(window).scroll(function() {
    window.requestAnimationFrame(scrollHandler);
});

if ($detailList.find('li').length === 0) {
    massageAJAX(1);
}