maybe-like.js 1.61 KB
/**
 * “你可能喜欢”模块JS
 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
 * @date: 2015/10/12
 */

var $ = require('yoho.zepto'),
    tip = require('../plugin/tip'),
    lazyLoad = require('yoho.zeptolazyload');

var winH = $(window).height(),
    loadMoreH = $('#load-more').height(),
    $goodList = $('#goods-list'),
    loading = false,
    page = 0,
    gender = $('.mobile-wrap').hasClass('boys-wrap') ? '1,3' : '2,3',
    kidsType = $('.mobile-wrap').hasClass('kids-wrap') ? true : false,
    lifestyleType = $('.mobile-wrap').hasClass('lifestyle-wrap') ? true : false,
    num,
    url;

///recom/maylikekids
if (kidsType) {
    url = '/product/recom/maylikekids';
} else if (lifestyleType) {
    url = '/product/recom/maylikelife';
} else {
    url = '/product/recom/maylike?gender=' + gender;
}

//srcoll to load more
$(window).scroll(function () {
    if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
        loading = true;
        num = $goodList.children('.good-info').length;
        $.ajax({
            type: 'GET',
            url: url,
            data: {
                page: page + 1
            },
            success: function(data) {
                $goodList.append(data);

                //lazyLoad
                //lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
                lazyLoad($('.good-info').find('img.lazy'));

                loading = false;
                page++;
            },
            error: function() {
                tip.show('网络断开连接了~');
                loading = false;
            }
        });
    }

});