currencyDetail.page.js 1.05 KB
require('scss/home/coin/yoho-coin-detail.page.scss');

let $ = require('yoho-jquery'),
    loading = require('js/plugin/loading'),
    currencyDetailHbs = require('hbs/home/ajax-currency-detail.hbs');

let page = 1,
    flag = true;

require('js/common');

function ajaxCurrencyDetail(curPage) {
    loading.showLoadingMask();
    flag = false;
    $.ajax({
        type: 'post',
        url: '/home/ajaxCurrencyDetail',
        dataType: 'json',
        data: {
            page: curPage
        },
        success: function(data) {
            if (data.length <= 0) {
                flag = false;
                return false;
            }

            loading.hideLoadingMask();
            $('.coin-detail').append(currencyDetailHbs({coinlist: data}));
            flag = true;
        }
    });
}

function scrollHandler() {
    if ($(window).scrollTop() + $(window).height() > $('body').height() - 100 && flag) {
        page++;
        ajaxCurrencyDetail(page);
        return;
    }
}

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