collocation-list.js 1.17 KB
/**
 * 星潮教室-星搭配分页加载
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/4/12
 */

var $ = require('jquery'),
    tip = require('../plugin/tip'),
    loading = require('../plugin/loading'),
    stopLoading = false;

var page = 1;

function massageAJAX(page) {
    loading.showLoadingMask();
    $.ajax({
        type: 'GET',
        url: '/guang/starclass/ajaxCollocation',
        data: {
            page: page
        },
        dataType: 'html',
        success: function(data) {
            stopLoading = false;

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

            $('.collocation-list').append(data);
            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() {
    scrollHandler();
});

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