|
@@ -12,16 +12,23 @@ var $goodsContainer = $('.goods-container'), |
|
@@ -12,16 +12,23 @@ var $goodsContainer = $('.goods-container'), |
12
|
$goodItemWrapper = $goodsContainer.find('.good-item-wrapper'),
|
12
|
$goodItemWrapper = $goodsContainer.find('.good-item-wrapper'),
|
13
|
$goodInfoMain = $goodsContainer.find('.good-info-main'),
|
13
|
$goodInfoMain = $goodsContainer.find('.good-info-main'),
|
14
|
$goodSelectColor = $goodsContainer.find('.good-select-color'),
|
14
|
$goodSelectColor = $goodsContainer.find('.good-select-color'),
|
15
|
- $productListNav = $('.product-list-nav');
|
|
|
16
|
-
|
|
|
17
|
-var productList = productEvent($goodItem, 5);
|
15
|
+ $productListNav = $('.product-list-nav'),
|
|
|
16
|
+ productList;
|
18
|
|
17
|
|
19
|
/**
|
18
|
/**
|
|
|
19
|
+ * @description 初始化鼠标移入商品列表弹层效果
|
|
|
20
|
+ * @num 每列存放商品的个数
|
|
|
21
|
+ */
|
|
|
22
|
+exports.init = function(num) {
|
|
|
23
|
+
|
|
|
24
|
+ productList = productEvent($goodItem, num);
|
|
|
25
|
+
|
|
|
26
|
+ /**
|
20
|
* @description 构造商品颜色列表的html结构
|
27
|
* @description 构造商品颜色列表的html结构
|
21
|
* @param data 商品颜色的数组,[url: '',src: '']
|
28
|
* @param data 商品颜色的数组,[url: '',src: '']
|
22
|
* @return json {'colorListStr': '', 'ulNum': ''}
|
29
|
* @return json {'colorListStr': '', 'ulNum': ''}
|
23
|
* */
|
30
|
* */
|
24
|
-function createColorList(data) {
|
31
|
+ function createColorList(data) {
|
25
|
var colorListStr = '',
|
32
|
var colorListStr = '',
|
26
|
len = data.length,
|
33
|
len = data.length,
|
27
|
row = 4, //每列ul放4个li
|
34
|
row = 4, //每列ul放4个li
|
|
@@ -58,9 +65,11 @@ function createColorList(data) { |
|
@@ -58,9 +65,11 @@ function createColorList(data) { |
58
|
colorListStr: colorListStr,
|
65
|
colorListStr: colorListStr,
|
59
|
ulNum: col
|
66
|
ulNum: col
|
60
|
};
|
67
|
};
|
61
|
-}
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ productList.addHandler('MouseEnter', function(event) {
|
|
|
71
|
+
|
62
|
|
72
|
|
63
|
-productList.addHandler('MouseEnter', function(event) {
|
|
|
64
|
|
73
|
|
65
|
var itemMr = 10, //list的右边距
|
74
|
var itemMr = 10, //list的右边距
|
66
|
itemMb = 35, //list的下边距
|
75
|
itemMb = 35, //list的下边距
|
|
@@ -68,8 +77,11 @@ productList.addHandler('MouseEnter', function(event) { |
|
@@ -68,8 +77,11 @@ productList.addHandler('MouseEnter', function(event) { |
68
|
ulNum,
|
77
|
ulNum,
|
69
|
wrapperWidth,
|
78
|
wrapperWidth,
|
70
|
diffWidth,
|
79
|
diffWidth,
|
71
|
- wrapperX = (event.targetX - 1) * (event.targetWidth + itemMr) - 21,
|
|
|
72
|
- wrapperY = (event.targetY - 1) * (event.targetHeight + itemMb) + 25 - 19;
|
80
|
+ wrapperX,
|
|
|
81
|
+ wrapperY,
|
|
|
82
|
+ wrapperPl, //鼠标移入时弹层的左内边距
|
|
|
83
|
+ wrapperPt, //鼠标移入时弹层的上内边距
|
|
|
84
|
+ containerPt; //商品列表容器的上内边距
|
73
|
|
85
|
|
74
|
$goodInfoMain.html('');
|
86
|
$goodInfoMain.html('');
|
75
|
$goodSelectColor.html('');
|
87
|
$goodSelectColor.html('');
|
|
@@ -82,15 +94,25 @@ productList.addHandler('MouseEnter', function(event) { |
|
@@ -82,15 +94,25 @@ productList.addHandler('MouseEnter', function(event) { |
82
|
dataType: 'json'
|
94
|
dataType: 'json'
|
83
|
}).then(function(data) {
|
95
|
}).then(function(data) {
|
84
|
|
96
|
|
85
|
- ulStr = createColorList(data).colorListStr;
|
|
|
86
|
- ulNum = createColorList(data).ulNum;
|
97
|
+ ulStr = createColorList(data).colorListStr; //ajax请求的颜色列表
|
|
|
98
|
+ ulNum = createColorList(data).ulNum;//ajax请求的颜色的数量
|
87
|
|
99
|
|
88
|
$goodInfoMain.append(event.targetDuplicate);
|
100
|
$goodInfoMain.append(event.targetDuplicate);
|
89
|
$goodSelectColor.append($(ulStr));
|
101
|
$goodSelectColor.append($(ulStr));
|
|
|
102
|
+
|
|
|
103
|
+ wrapperPl = $goodItemWrapper.css('paddingLeft');
|
|
|
104
|
+ wrapperPt = $goodItemWrapper.css('paddingTop');
|
|
|
105
|
+ containerPt = $goodsContainer.css('paddingTop');
|
|
|
106
|
+
|
90
|
wrapperWidth = 10 + (15 + 50) * ulNum + event.targetWidth;
|
107
|
wrapperWidth = 10 + (15 + 50) * ulNum + event.targetWidth;
|
91
|
|
108
|
|
|
|
109
|
+ wrapperX = (event.targetX - 1) * (event.targetWidth + itemMr) - (parseInt(wrapperPl) + 1);
|
|
|
110
|
+ wrapperY = (event.targetY - 1) *
|
|
|
111
|
+ (event.targetHeight + itemMb) + parseInt(containerPt) - (parseInt(wrapperPt) + 1);
|
|
|
112
|
+
|
92
|
//todo
|
113
|
//todo
|
93
|
diffWidth = event.offsetR - ((15 + 50) * ulNum + 25);
|
114
|
diffWidth = event.offsetR - ((15 + 50) * ulNum + 25);
|
|
|
115
|
+
|
94
|
if (diffWidth <= 0) {
|
116
|
if (diffWidth <= 0) {
|
95
|
wrapperX = wrapperX + diffWidth;
|
117
|
wrapperX = wrapperX + diffWidth;
|
96
|
}
|
118
|
}
|
|
@@ -102,21 +124,22 @@ productList.addHandler('MouseEnter', function(event) { |
|
@@ -102,21 +124,22 @@ productList.addHandler('MouseEnter', function(event) { |
102
|
});
|
124
|
});
|
103
|
|
125
|
|
104
|
});
|
126
|
});
|
105
|
-});
|
127
|
+ });
|
106
|
|
128
|
|
107
|
-$goodItemWrapper.mouseleave(function() {
|
129
|
+ $goodItemWrapper.mouseleave(function() {
|
108
|
$goodInfoMain.html('');
|
130
|
$goodInfoMain.html('');
|
109
|
$goodSelectColor.html('');
|
131
|
$goodSelectColor.html('');
|
110
|
$goodItemWrapper.css({
|
132
|
$goodItemWrapper.css({
|
111
|
display: 'none'
|
133
|
display: 'none'
|
112
|
});
|
134
|
});
|
113
|
-});
|
135
|
+ });
|
114
|
|
136
|
|
115
|
-// 左侧导航
|
|
|
116
|
-$productListNav.click(function() {
|
137
|
+ // 左侧导航
|
|
|
138
|
+ $productListNav.click(function() {
|
117
|
if ($(this).hasClass('active')) {
|
139
|
if ($(this).hasClass('active')) {
|
118
|
$(this).removeClass('active');
|
140
|
$(this).removeClass('active');
|
119
|
} else {
|
141
|
} else {
|
120
|
$(this).addClass('active');
|
142
|
$(this).addClass('active');
|
121
|
}
|
143
|
}
|
122
|
-}); |
|
|
|
|
144
|
+ });
|
|
|
145
|
+}; |