Authored by zhangxiaoru

swiper初始化

@@ -164,7 +164,6 @@ const _getBrandListOriginData = (channel) => { @@ -164,7 +164,6 @@ const _getBrandListOriginData = (channel) => {
164 } else { 164 } else {
165 return {}; 165 return {};
166 } 166 }
167 -  
168 }); 167 });
169 }; 168 };
170 169
@@ -246,12 +245,12 @@ const indexData = (gender, brandCode, cateCode) => { @@ -246,12 +245,12 @@ const indexData = (gender, brandCode, cateCode) => {
246 if (result[1]) { 245 if (result[1]) {
247 _.forEach(result[1], function(data) { 246 _.forEach(result[1], function(data) {
248 if (data.focus_type && data.focus_type === '1') { 247 if (data.focus_type && data.focus_type === '1') {
249 - //brandList.bannerTop = _dealBrandUrl(data); 248 + // brandList.bannerTop = _dealBrandUrl(data);
250 brandList.bannerTop = data; 249 brandList.bannerTop = data;
251 } else if (data.focus_type && data.focus_type === '2') { 250 } else if (data.focus_type && data.focus_type === '2') {
252 - //brandList.focusData = _dealBrandUrl(data).data; 251 + // brandList.focusData = _dealBrandUrl(data).data;
253 brandList.focusData = data.data; 252 brandList.focusData = data.data;
254 - } else if (data.template_intro === '一张图片') { 253 + } else if (data.template_name === 'single_image') {
255 brandList.bannerTop = data; 254 brandList.bannerTop = data;
256 } 255 }
257 }); 256 });
@@ -296,12 +295,12 @@ const brandListData = (code, gender) => { @@ -296,12 +295,12 @@ const brandListData = (code, gender) => {
296 if (result[0]) { 295 if (result[0]) {
297 _.forEach(result[0], function(data) { 296 _.forEach(result[0], function(data) {
298 if (data.focus_type && data.focus_type === '1') { 297 if (data.focus_type && data.focus_type === '1') {
299 - //brandList.bannerTop = _dealBrandUrl(data); 298 + // brandList.bannerTop = _dealBrandUrl(data);
300 brandList.bannerTop = data; 299 brandList.bannerTop = data;
301 } else if (data.focus_type && data.focus_type === '2') { 300 } else if (data.focus_type && data.focus_type === '2') {
302 - //brandList.focusData = _dealBrandUrl(data).data; 301 + // brandList.focusData = _dealBrandUrl(data).data;
303 brandList.focusData = data.data; 302 brandList.focusData = data.data;
304 - } else if (data.template_intro === '一张图片') { 303 + } else if (data.template_name === 'single_image') {
305 brandList.bannerTop = data; 304 brandList.bannerTop = data;
306 } 305 }
307 }); 306 });
1 var $ = require('yoho-jquery'), 1 var $ = require('yoho-jquery'),
2 Swiper = require('yoho-swiper2'); 2 Swiper = require('yoho-swiper2');
3 3
4 -var bannerSwiper,  
5 - categoryHeight = $('.tab-box').height(), 4 +var categoryHeight = $('.tab-box').height(),
6 gender, 5 gender,
7 isBrand; 6 isBrand;
8 7
@@ -16,7 +15,25 @@ function channels(key) { @@ -16,7 +15,25 @@ function channels(key) {
16 'women': 2, 15 'women': 2,
17 'lifestyle': 4 16 'lifestyle': 4
18 }[key]; 17 }[key];
19 -}; 18 +}
  19 +
  20 +function initialize() {
  21 + $('.banner-swiper').each(function() {
  22 + if ($(this).hasClass('swiper-container-horizontal') === false && $(this).find('li').length > 1) {
  23 + new Swiper(this, {
  24 + preloadImages: false,
  25 + lazyLoading: true,
  26 + lazyLoadingInPrevNext: true,
  27 + lazyLoadingOnTransitionStart: true,
  28 + loop: true,
  29 + autoplay: 3000,
  30 + autoplayDisableOnInteraction: false,
  31 + paginationClickable: true,
  32 + slideElement: 'li'
  33 + });
  34 + }
  35 + });
  36 +}
20 37
21 function loadData(channel, isBrand) { 38 function loadData(channel, isBrand) {
22 var preUrl; 39 var preUrl;
@@ -38,19 +55,21 @@ function loadData(channel, isBrand) { @@ -38,19 +55,21 @@ function loadData(channel, isBrand) {
38 $('.brand-content').html(data); 55 $('.brand-content').html(data);
39 } else { 56 } else {
40 $('.category-content').html(data); 57 $('.category-content').html(data);
41 - } 58 + }
  59 +
  60 + initialize();
42 } 61 }
43 }); 62 });
44 } 63 }
45 64
46 $('.channel-tab').find('li').click(function() { 65 $('.channel-tab').find('li').click(function() {
47 - gender = $(this).find('span').text().replace(/[^A-Za-z]+/g, '').toLowerCase(), 66 + gender = $(this).find('span').text().replace(/[^A-Za-z]+/g, '').toLowerCase();
48 isBrand = $('.brand-tab').find('.brand').hasClass('active'); 67 isBrand = $('.brand-tab').find('.brand').hasClass('active');
49 68
50 $(this).addClass('focus').siblings().removeClass('focus'); 69 $(this).addClass('focus').siblings().removeClass('focus');
51 70
52 loadData(channels(gender), isBrand); 71 loadData(channels(gender), isBrand);
53 -}) 72 +});
54 73
55 // 点击字母,页面滚动到相关区域 74 // 点击字母,页面滚动到相关区域
56 $intercept.click(function() { 75 $intercept.click(function() {
@@ -75,21 +94,7 @@ $('.brand-tab').find('li').click(function() { @@ -75,21 +94,7 @@ $('.brand-tab').find('li').click(function() {
75 $('.cate-cha').removeClass('hide').siblings().addClass('hide'); 94 $('.cate-cha').removeClass('hide').siblings().addClass('hide');
76 } 95 }
77 96
78 - $('.banner-swiper').each(function() {  
79 - if ($(this).hasClass('swiper-container-horizontal') === false && $(this).find('li').length > 1) {  
80 - new Swiper(this, {  
81 - preloadImages: false,  
82 - lazyLoading: true,  
83 - lazyLoadingInPrevNext: true,  
84 - lazyLoadingOnTransitionStart: true,  
85 - loop: true,  
86 - autoplay: 3000,  
87 - autoplayDisableOnInteraction: false,  
88 - paginationClickable: true,  
89 - slideElement: 'li'  
90 - });  
91 - }  
92 - }); 97 + initialize();
93 }); 98 });
94 99
95 $(function() { 100 $(function() {