currency-detail.page.js 818 Bytes
var $ = require('yoho-jquery'),
    loading = require('../plugin/loading');
var page = 1;
var flag = true;

loading.showLoadingMask();

function ajaxCurrencyDetail(curPage) {
    flag = false;
    $.ajax({
        type: 'post',
        url: '/home/ajaxCurrencyDetail',
        dataType: 'html',
        data: {
            page: curPage
        },
        success: function(data) {
            $('.coin-detail').append(data);
            flag = true;
        }
    });
}

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

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

ajaxCurrencyDetail(page);

$(document).ready(loading.hideLoadingMask);