list.js 1.67 KB
/**
 * 商品列表页
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/23
 */

 var $ = require('yoho.jquery'),
    lazyLoad = require('yoho.lazyload');

require('yoho.placeholder');

require('./filter');

require('./sort-pager');

require('./product');


//最近浏览的商品Lazyload
lazyLoad($('.latest-walk .lazy'));

//无搜索结果
if ($('.no-result').length > 0) {
    $('#no-result-input').placeholder();
    $('#search-again-btn').click(function() {
        $(this).closest('form').submit();
    });
}

//NEW页面图片轮播切换
(function() {
    var $brands = $('.brands');

    var wrapWidth,
        $firstBrand,
        totalWidth,
        perWidth;

    if ($brands.length === 0) {
        return;
    }

    wrapWidth = $('.brands-wrap').width();

    $firstBrand = $brands.children('li:first-child');
    perWidth = $firstBrand.width() + $firstBrand.css('margin-left').replace('px', '') * 1;

    totalWidth = perWidth * $brands.children('li').length;

    //针对NEW页面Header的brand banner切换
    $('.new-brands').on('click', '.pre,.next', function() {
        var $this = $(this),
            left;

        left = $brands.css('left');

        if (left === 'auto') {
            left = 0;
        } else {
            left = +left.replace('px', '');
        }

        if (($this).hasClass('pre')) {

            //左边界
            if (left + wrapWidth > 0) {
                return;
            }
            $brands.css('left', left + wrapWidth + 'px');
        } else {

            //右边界
            if (left - wrapWidth < -totalWidth) {
                return;
            }
            $brands.css('left', left - wrapWidth + 'px');
        }
    });
}());