Authored by lore-w

优化品牌收藏swiper

@@ -12,7 +12,6 @@ var diaLog = require('./dialog'); @@ -12,7 +12,6 @@ var diaLog = require('./dialog');
12 12
13 var $navLi = $('#fav-tab > li'), 13 var $navLi = $('#fav-tab > li'),
14 $favContainer = $('.fav-content > .fav-type'), 14 $favContainer = $('.fav-content > .fav-type'),
15 - $swiperList = '',  
16 swiperObj = {}, 15 swiperObj = {},
17 favTabHammer, 16 favTabHammer,
18 favContentHammer, 17 favContentHammer,
@@ -37,22 +36,30 @@ function showFavTab(index) { @@ -37,22 +36,30 @@ function showFavTab(index) {
37 } 36 }
38 37
39 //初始化swiper 38 //初始化swiper
40 -function initSwiper() { 39 +function initSwiper(data) {
41 var i, 40 var i,
42 - id; 41 + idStrReg = /container-(\d+)['"]{1}/gi,
  42 + idReg = /\d+/,
  43 + idArr = data.match(idStrReg),
  44 + idArrLen = idArr.length,
  45 + containerId;
43 46
44 - $swiperList = $('.swiper-container');  
45 - for (i = 0; i < $swiperList.length; i++) {  
46 - id = $swiperList.eq(i).attr('data-id'); 47 + //$swiperList = $('.swiper-container');
  48 + for (i = 0; i < idArrLen; i++) {
  49 +
  50 + /*id = $swiperList.eq(i).attr('data-id');
47 51
48 if (!!swiperObj[id]) { 52 if (!!swiperObj[id]) {
49 swiperObj[id].destroy(true, true); 53 swiperObj[id].destroy(true, true);
50 - }  
51 - swiperObj[id] = new Swiper('#swiper-container-' + id, { 54 + }*/
  55 +
  56 + containerId = idArr[i].match(idReg)[0];
  57 +
  58 + swiperObj[containerId] = new Swiper('#swiper-container-' + containerId, {
52 slidesPerView: 'auto', 59 slidesPerView: 'auto',
53 grabCursor: true, 60 grabCursor: true,
54 slideElement: 'li', 61 slideElement: 'li',
55 - wrapperClass: 'swiper-wrapper-' + id, 62 + wrapperClass: 'swiper-wrapper-' + containerId,
56 lazyLoading: true, 63 lazyLoading: true,
57 watchSlidesVisibility: true 64 watchSlidesVisibility: true
58 }); 65 });
@@ -93,7 +100,7 @@ function loadData($parent, url, page) { @@ -93,7 +100,7 @@ function loadData($parent, url, page) {
93 $parent.append(data); 100 $parent.append(data);
94 $parent.closest('.fav-type').find('.fav-content-loading').remove(); 101 $parent.closest('.fav-type').find('.fav-content-loading').remove();
95 if (url === 'favBrand') { 102 if (url === 'favBrand') {
96 - initSwiper();//如果是收藏品牌需要初始化swiper 103 + initSwiper(data);//如果是收藏品牌需要初始化swiper
97 104
98 brandLockId = false;//请求成功后解锁品牌收藏page++ 105 brandLockId = false;//请求成功后解锁品牌收藏page++
99 } else { 106 } else {
@@ -39,7 +39,7 @@ $('#upload-img').uploadifive({ @@ -39,7 +39,7 @@ $('#upload-img').uploadifive({
39 fileType: 'image*/*', 39 fileType: 'image*/*',
40 uploadScript: '/home/suggestimgUpload', 40 uploadScript: '/home/suggestimgUpload',
41 fileObjName: 'fileData', 41 fileObjName: 'fileData',
42 - fileSizeLimit: 1024, 42 + fileSizeLimit: 300,
43 height: '100%', 43 height: '100%',
44 width: '100%', 44 width: '100%',
45 multi: false, 45 multi: false,