Blame view

static/js/product/detail/desc.js 3.18 KB
梁志锋 authored
1
/**
Lynnic authored
2
 *  商品详情  --异步加载页面下半部分
梁志锋 authored
3 4 5 6
 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
 * @date: 2015/11/18
 */
var $ = require('jquery'),
Lynnic authored
7
    lazyLoad = require('yoho.lazyload'),
Lynnic authored
8 9
    Swiper = require('yoho.iswiper'),
    loading = require('../../plugin/loading'),
梁志锋 authored
10 11 12 13
    tip = require('../../plugin/tip');

var introUrl = $('#introUrl').val(),
    winH = $(window).height(),
梁志锋 authored
14
    $productDesc,
梁志锋 authored
15
    searching = false,
梁志锋 authored
16
    end = false;
梁志锋 authored
17
Lynnic authored
18
var sizeSwiper,
Lynnic authored
19
    refSwiper;
Lynnic authored
20
21
22 23
//判断是否要显示向左滑动提示
function hiddenTips($ele) {
24 25 26
    var offsetContainer,
        offsetLastColumn;
Lynnic authored
27
    if ($ele.length > 0) {
28 29
        offsetContainer = $ele[0].getBoundingClientRect().right;
        offsetLastColumn = $ele.find('.swiper-slide:last-child')[0].getBoundingClientRect().right;
30 31

Lynnic authored
32 33 34 35 36
        if (offsetLastColumn - offsetContainer < 0) {
            $ele.next('.tips').css('display', 'none');
        } else {
            $ele.next('.tips').css('display', 'block');
        }
37 38 39
    }
}
40 41 42 43 44 45 46 47 48 49 50 51 52
//function isFlexSupport() {
//    var flex = document.createElement('p').style.flex,
//        webkitFlex = document.createElement('p').style.webkitFlex,
//        flexWrap = document.createElement('p').style.flexWrap;
//
//    if ((flex === '' || webkitFlex === '') && flexWrap === '') {
//        return true;
//    } else {
//        return false;
//    }
//}

function wrapElements(selector, count) {
53 54
    var elArr = null;
55
    $(selector).each(function(idx, el) {
56 57 58 59
        elArr = $(selector).slice(idx, idx + count);

        if (elArr.length === count && idx % count === 0) {
            $(elArr).wrapAll($('<div class="js-wraper"></div>'));
60 61
        }
    });
62 63
}
64
65
梁志锋 authored
66 67 68 69 70 71
function search() {
    if (searching || end) {
        return;
    }
    searching = true;
72 73
    // alert($('#reference-swiper-container .swiper-wrapper').width());
梁志锋 authored
74 75 76 77 78 79
    loading.showLoadingMask();

    $.ajax({
        type: 'GET',
        url: introUrl,
        success: function(data) {
梁志锋 authored
80
            $productDesc = $('#productDesc');
梁志锋 authored
81 82
            $productDesc.append(data);
83 84
            window.rePosFooter();
梁志锋 authored
85 86
            lazyLoad($productDesc.find('img.lazy'));
Lynnic authored
87 88 89 90 91 92 93 94 95 96
            //尺码信息左右滑动
            sizeSwiper = new Swiper('#size-swiper-container',{
                slidesPerView: 'auto'
            });

            //模特试穿左右滑动
            refSwiper = new Swiper('#reference-swiper-container',{
                slidesPerView: 'auto'
            });
97 98
            hiddenTips($('#size-swiper-container'));
            hiddenTips($('#reference-swiper-container'));
99
100 101 102 103
            //if (!isFlexSupport()) {
            //    $('.detail .column').removeClass('column').addClass('oldbox');
            //}
            wrapElements('.detail .column', 2);
梁志锋 authored
104 105 106 107 108 109 110 111 112 113 114 115
            searching = false;
            end = true;
            loading.hideLoadingMask();
        },
        error: function() {
            tip.show('网络断开连接了~');
            searching = false;
            loading.hideLoadingMask();
        }
    });
}
梁志锋 authored
116
function scrollHandler() {
梁志锋 authored
117
    if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) {
梁志锋 authored
118 119 120 121
        search();
    }
}
梁志锋 authored
122
//srcoll to load more
梁志锋 authored
123
$(window).scroll(function() {
梁志锋 authored
124 125 126
    window.requestAnimationFrame(scrollHandler);
});