Blame view

public/js/guang/detail-list.page.js 1.39 KB
王水玲 authored
1 2 3 4 5
/**
 * 星潮教室-明星专题列表
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/6/7
 */
lijing authored
6
let $ = require('yoho-jquery'),
陈峰 authored
7 8
    tip = require('js/plugin/tip'),
    loading = require('js/plugin/loading'),
郭成尧 authored
9
    lazyLoad = require('yoho-jquery-lazyload');
王水玲 authored
10
lijing authored
11
let $detailList = $('.detail-list'),
王水玲 authored
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    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() {
王水玲 authored
55
    window.requestAnimationFrame(scrollHandler);
王水玲 authored
56 57 58 59 60
});

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