Authored by lore-w

商品列表页鼠标移入效果适配、product.js优化适配每列不同的商品数量

@@ -20,6 +20,17 @@ @@ -20,6 +20,17 @@
20 {{!-- 搜索 --}} 20 {{!-- 搜索 --}}
21 {{#if searchListPage}} 21 {{#if searchListPage}}
22 <script> 22 <script>
23 - seajs.use(['js/product/list', 'js/product/product']); 23 + seajs.use(['js/product/list', 'js/product/product'], function (list, product) {
  24 + product.init(5);
  25 + });
24 </script> 26 </script>
25 {{/if}} 27 {{/if}}
  28 +
  29 +{{!-- 列表 --}}
  30 +{{#if productListPage}}
  31 +<script>
  32 + seajs.use(['js/product/list', 'js/product/product'], function (list, product) {
  33 + product.init(4);
  34 + });
  35 +</script>
  36 +{{/if}}
@@ -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 +};
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 //图片 8 //图片
9 .good-detail-img { 9 .good-detail-img {
10 width: 100%; 10 width: 100%;
11 - height: 300px; 11 + /*height: 300px;*/
12 position: relative; 12 position: relative;
13 13
14 .good-thumb, img.lazy { 14 .good-thumb, img.lazy {
@@ -204,6 +204,11 @@ @@ -204,6 +204,11 @@
204 height: auto; 204 height: auto;
205 padding: 25px 0 0 0; 205 padding: 25px 0 0 0;
206 position: relative; 206 position: relative;
207 - width: 1150px + 10px;//每列增加右边距 207 + width: 970px + 10px;//每列增加右边距
  208 +
  209 + .good-info {
  210 + width: 235px;
  211 +
  212 + }
208 } 213 }
209 } 214 }
@@ -383,7 +383,8 @@ class IndexController extends AbstractAction @@ -383,7 +383,8 @@ class IndexController extends AbstractAction
383 public function listAction() 383 public function listAction()
384 { 384 {
385 $data = array( 385 $data = array(
386 - 'searchListPage' => true, 386 + //'searchListPage' => true,
  387 + 'productListPage' => true, //初始化js
387 388
388 'list' => array( 389 'list' => array(
389 'brandBanner' => array( 390 'brandBanner' => array(