product-category.js
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* 分类
* @author: berry<lixia.zhang@yoho.cn>
* @date: 2016/4/25
*/
var $ = require('jquery');
var $allProductCell = $('.allproduct'),
$categoryContainer = $('.category-container'),
$contents = $categoryContainer.children('.content'),
$subLevelItem = $categoryContainer.find('.sub-level li'),
$trilangle = $categoryContainer.find('.primary-level-trilangle');
//初始化container高度
(function() {
var $header = $('.yoho-header');
var h = $(window).height() - $header.outerHeight() - $allProductCell.outerHeight();
var trilangleRightMargin = $(window).width() * 0.55;
$categoryContainer.css('min-height', h);
$trilangle.css('margin-right', trilangleRightMargin);
$contents.height(h);
}());
$categoryContainer.on('touchend', function(e) {
var $this = $(e.target),
$subLevel,
$cur, index,
$subLevelContainer, $trilangleItem;
$cur = $this.closest('.p-level-item');
//第一次单击右则空白处,出现冒泡
if ($(e.target).closest('.sub-level').length <=0) {
e.preventDefault();
}
$subLevelContainer = $this.closest('.content').find('.sub-level-container');
$subLevelContainer.removeClass('hide');
if ($cur.length > 0) {
index = $cur.index();
$subLevel = $this.closest('.content').find('.sub-level');
$trilangleItem = $this.closest('.content').find('.primary-level-trilangle');
if ($this.hasClass('focus')) {
return;
}
$subLevel.not('.hide').addClass('hide');
$subLevel.eq(index).removeClass('hide');
$trilangleItem.not('.hide').addClass('hide');
$trilangleItem.eq(index).removeClass('hide');
}
});
$categoryContainer.find('.sub-level').on('touchstart', 'li', function() {
$subLevelItem.removeClass('highlight');
$(this).addClass('highlight');
}).on('touchend touchcancel', 'li', function() {
$(this).removeClass('highlight');
});
$allProductCell.on('touchstart', function() {
$(this).addClass('highlight');
}).on('touchend touchcancel', function() {
$(this).removeClass('highlight');
});