template.js 1.74 KB
/**
 * 模板页js
 * @author: xuqi(qi.xu@yoho.cn)
 * @date;2015/4/14
 */

var $ = require('jquery'),
    timer = null;

require('lazyload');

/**
 * 页面加载初始化
 */
exports.init = function() {
    $(function() {
        var $navItem = $('#goods-nav .nav-item'),
            $goodsContainer = $('#goods-container'),
            $goodList = $('#goods-container > div'),
            $npc = $goodList.filter('.new-patterns-container'),
            $svc = $goodList.filter('.sales-volume-container'),
            $pc = $goodList.filter('.price-container');

        //img lazyload
        $('img.lazy').lazyload({
            skip_invisible : false
        });

        /**
         * 导航 touch/click处理句柄
         */
        function touchEvt(e) {
            var $cur = $(e.currentTarget);

            if ($cur.hasClass('focus')) {
                return;
            }

            $navItem.removeClass('focus');
            $cur.addClass('focus');

            if ($cur.hasClass('screen-nav')) {
                //筛选
            } else {
                $goodList.addClass('hide');
                if ($cur.hasClass('new-patterns-nav')) {
                    $npc.removeClass('hide');
                } else if ($cur.hasClass('sales-volume-nav')) {
                    $svc.removeClass('hide');
                } else if ($cur.hasClass('price-nav')) {
                    $pc.removeClass('hide');
                }
            }
        }

        //切换“最新”,“销量”,“价格”以及“筛选”功能
        $('#goods-nav').delegate('.nav-item', 'touchstart', function(e) {
            e.preventDefault();
            touchEvt(e);
        }).delegate('.nav-item', 'click', function(e) {
            touchEvt(e);
        });
    });
};