brand.js 1.85 KB
/**
 *  品牌一览
 * @author: liangzhifeng<zhifeng.liang@yoho.cn>
 * @date: 2015/10/23
 */

var $ = require('jquery'),
    Hammer = require('hammer'),
    Swiper = require('yoho.iswiper'),
    lazyLoad = require('yoho.lazyload');

var swiper,
    $brandList = $('.brand-list');

var searchH = $('.newbrand-search').height(),
    headerH = $('.yoho-header').height(),
    brandSwipe = parseInt(searchH) + parseInt(headerH);

var myHammer;

swiper = new Swiper('.swiper-container', {
    lazyLoading: true,
    loop: true,
    autoplay: 3000,
    pagination: '.swiper-pagination .pagination-inner'
});

lazyLoad($('img.lazy'));
$('.yoho-header').css({
    'z-index': 2,
    position: 'fixed'
});
$('.banner-top').css('padding-top', '90px');

if ($brandList.length > 0) {
    $(window).scroll(function() {
        var scrTop = $(window).scrollTop();

        $('.brand-list').each(function() {
            var offTop = $(this).offset().top - brandSwipe;

            if (scrTop >= offTop) {
                $brandList.find('.title-bar').css('position', 'static');
                $(this).find('.title-bar').css({
                    position: 'fixed',
                    top: brandSwipe
                });
            } else {
                $(this).find('.title-bar').css('position', 'static');
            }
        });
    });
}

// $('#right-bar .con').find('b').unbind().on('tap', function() {
//     var index = $(this).index();

//     if ($('.bar-' + index).size() > 0) {
//         document.body.scrollTop = parseInt($('.bar-' + index)[0].offsetTop) - parseInt(brandSwipe - 1);
//     }
// });

myHammer = new Hammer($('#right-bar .con').find('b').unbind()[0]);
myHammer.on('tap', function(e) {
    var index = $(this).index();

    if ($('.bar-' + index).size() > 0) {
        document.body.scrollTop = parseInt($('.bar-' + index)[0].offsetTop) - parseInt(brandSwipe - 1);
    }
});