Showing
5 changed files
with
74 additions
and
38 deletions
@@ -4,8 +4,7 @@ | @@ -4,8 +4,7 @@ | ||
4 | * @date: 2015/10/10 | 4 | * @date: 2015/10/10 |
5 | */ | 5 | */ |
6 | 6 | ||
7 | -var $ = require('jquery'), | ||
8 | - Swiper = require('yoho.iswiper'); | 7 | +var $ = require('jquery'); |
9 | 8 | ||
10 | var info = require('./info'), | 9 | var info = require('./info'), |
11 | loadMore = info.loadMore; | 10 | loadMore = info.loadMore; |
@@ -24,18 +23,12 @@ var $infoList = $('#info-list'), | @@ -24,18 +23,12 @@ var $infoList = $('#info-list'), | ||
24 | 23 | ||
25 | var state = {}; | 24 | var state = {}; |
26 | 25 | ||
27 | -var mySwiper; | ||
28 | - | ||
29 | if ($loadMoreInfo.length > 0) { | 26 | if ($loadMoreInfo.length > 0) { |
30 | $loading = $loadMoreInfo.children('.loading'); | 27 | $loading = $loadMoreInfo.children('.loading'); |
31 | $noMore = $loadMoreInfo.children('.no-more'); | 28 | $noMore = $loadMoreInfo.children('.no-more'); |
32 | } | 29 | } |
33 | 30 | ||
34 | -mySwiper = new Swiper('.swiper-container', { | ||
35 | - lazyLoading: true, | ||
36 | - pagination: '.swiper-pagination', | ||
37 | - autoplay: 3000 | ||
38 | -}); | 31 | +info.initSwiper(curType); |
39 | 32 | ||
40 | info.initInfosEvt($infoList); | 33 | info.initInfosEvt($infoList); |
41 | 34 |
@@ -7,16 +7,19 @@ | @@ -7,16 +7,19 @@ | ||
7 | var $ = require('jquery'), | 7 | var $ = require('jquery'), |
8 | Hammer = require('yoho.hammer'), | 8 | Hammer = require('yoho.hammer'), |
9 | ellipsis = require('mlellipsis'), | 9 | ellipsis = require('mlellipsis'), |
10 | - lazyLoad = require('yoho.lazyload'); | 10 | + lazyLoad = require('yoho.lazyload'), |
11 | + Swiper = require('yoho.iswiper'); | ||
11 | 12 | ||
12 | var tip = require('../plugin/tip'); | 13 | var tip = require('../plugin/tip'); |
13 | var loading = require('../plugin/loading'); | 14 | var loading = require('../plugin/loading'); |
14 | 15 | ||
15 | var $loadMoreInfo = $('#load-more-info'); | 16 | var $loadMoreInfo = $('#load-more-info'); |
16 | var $loading = $(''), | 17 | var $loading = $(''), |
17 | - $noMore = $(''); | 18 | + $noMore = $(''), |
19 | + $swiper = $(''); | ||
18 | 20 | ||
19 | var searching = false; | 21 | var searching = false; |
22 | +var mySwiper = {}; | ||
20 | 23 | ||
21 | ellipsis.init(); | 24 | ellipsis.init(); |
22 | 25 | ||
@@ -25,6 +28,20 @@ if ($loadMoreInfo.length > 0) { | @@ -25,6 +28,20 @@ if ($loadMoreInfo.length > 0) { | ||
25 | $noMore = $loadMoreInfo.children('.no-more'); | 28 | $noMore = $loadMoreInfo.children('.no-more'); |
26 | } | 29 | } |
27 | 30 | ||
31 | +//初始化swiper | ||
32 | +function initSwiper(typeId) { | ||
33 | + console.log(typeId); | ||
34 | + if (typeof typeId === undefined) { | ||
35 | + return; | ||
36 | + } | ||
37 | + mySwiper[typeId] = new Swiper('.swiper-cont-' + typeId, { | ||
38 | + lazyLoading: true, | ||
39 | + wrapperClass: 'swiper-wrap-' + typeId, | ||
40 | + pagination: '.swiper-pagi-' + typeId, | ||
41 | + autoplay: 3000 | ||
42 | + }); | ||
43 | +} | ||
44 | + | ||
28 | /** | 45 | /** |
29 | * 设置指定资讯项的Lazyload和文字截取 | 46 | * 设置指定资讯项的Lazyload和文字截取 |
30 | * @params $infos 资讯项 | 47 | * @params $infos 资讯项 |
@@ -175,6 +192,14 @@ function loadMore($container, opt, url) { | @@ -175,6 +192,14 @@ function loadMore($container, opt, url) { | ||
175 | 192 | ||
176 | $container.append(data); | 193 | $container.append(data); |
177 | 194 | ||
195 | + $swiper = $container.find('.swiper-container'); | ||
196 | + if ($swiper.length) { | ||
197 | + $swiper.addClass('swiper-cont-' + opt.type); | ||
198 | + $swiper.children('.swiper-wrapper').addClass('swiper-wrap-' + opt.type); | ||
199 | + $swiper.children('.swiper-pagination').addClass('swiper-pagi-' + opt.type); | ||
200 | + initSwiper(opt.type); | ||
201 | + } | ||
202 | + | ||
178 | if (num > 0) { | 203 | if (num > 0) { |
179 | $newItems = $container.find('.guang-info:gt(' + (num - 1) + ')'); | 204 | $newItems = $container.find('.guang-info:gt(' + (num - 1) + ')'); |
180 | } else { | 205 | } else { |
@@ -202,6 +227,9 @@ function loadMore($container, opt, url) { | @@ -202,6 +227,9 @@ function loadMore($container, opt, url) { | ||
202 | }); | 227 | }); |
203 | } | 228 | } |
204 | 229 | ||
230 | + | ||
231 | +exports.mySwiper = mySwiper; | ||
232 | +exports.initSwiper = initSwiper; | ||
205 | exports.initInfosEvt = initInfosEvt; | 233 | exports.initInfosEvt = initInfosEvt; |
206 | exports.setLazyLoadAndMellipsis = setLazyLoadAndMellipsis; | 234 | exports.setLazyLoadAndMellipsis = setLazyLoadAndMellipsis; |
207 | exports.loadMore = loadMore; | 235 | exports.loadMore = loadMore; |
@@ -9,8 +9,32 @@ | @@ -9,8 +9,32 @@ | ||
9 | </li> | 9 | </li> |
10 | {{/ navs}} | 10 | {{/ navs}} |
11 | </ul> | 11 | </ul> |
12 | - <div class="guang-item-content"> | ||
13 | - {{> guang/home}} | 12 | + |
13 | + <div id="info-list" class="info-list-container"> | ||
14 | + {{# infos}} | ||
15 | + <div class="info-list{{^show}} hide{{/show}}"> | ||
16 | + {{#if show}} | ||
17 | + {{#if ../swiper}} | ||
18 | + <div class="swiper-container swiper-cont-{{@index}}"> | ||
19 | + <div class="swiper-wrapper swiper-wrap-{{@index}}"> | ||
20 | + {{# swiper}} | ||
21 | + <div class="swiper-slide"> | ||
22 | + <a href="{{url}}"> | ||
23 | + <img class="swiper-lazy" data-src="{{img}}"> | ||
24 | + </a> | ||
25 | + <div class="swiper-lazy-preloader"></div> | ||
26 | + </div> | ||
27 | + {{/ swiper}} | ||
28 | + </div> | ||
29 | + <div class="swiper-pagination swiper-pagi-{{@index}}"></div> | ||
30 | + </div> | ||
31 | + {{/if}} | ||
32 | + {{/if}} | ||
33 | + {{# info}} | ||
34 | + {{> guang/info}} | ||
35 | + {{/ info}} | ||
36 | + </div> | ||
37 | + {{/ infos}} | ||
14 | </div> | 38 | </div> |
15 | 39 | ||
16 | <div id="load-more-info" class="load-more-info"> | 40 | <div id="load-more-info" class="load-more-info"> |
1 | +{{#if swiper}} | ||
2 | + <div class="swiper-container"> | ||
3 | + <div class="swiper-wrapper"> | ||
4 | + {{# swiper}} | ||
5 | + <div class="swiper-slide"> | ||
6 | + <a href="{{url}}"> | ||
7 | + <img class="swiper-lazy" data-src="{{img}}"> | ||
8 | + </a> | ||
9 | + <div class="swiper-lazy-preloader"></div> | ||
10 | + </div> | ||
11 | + {{/ swiper}} | ||
12 | + </div> | ||
13 | + <div class="swiper-pagination"></div> | ||
14 | + </div> | ||
15 | +{{/if}} | ||
16 | + | ||
1 | {{# infos}} | 17 | {{# infos}} |
2 | {{> guang/info}} | 18 | {{> guang/info}} |
3 | {{/ infos}} | 19 | {{/ infos}} |
1 | -{{#if swiper}} | ||
2 | - <div class="swiper-container"> | ||
3 | - <div class="swiper-wrapper"> | ||
4 | - {{# swiper}} | ||
5 | - <div class="swiper-slide"> | ||
6 | - <a href="{{url}}"> | ||
7 | - <img class="swiper-lazy" data-src="{{img}}"> | ||
8 | - </a> | ||
9 | - <div class="swiper-lazy-preloader"></div> | ||
10 | - </div> | ||
11 | - {{/ swiper}} | ||
12 | - </div> | ||
13 | - <div class="swiper-pagination"></div> | ||
14 | - </div> | ||
15 | -{{/if}} | ||
16 | - | ||
17 | -<div id="info-list" class="info-list-container"> | ||
18 | - {{# infos}} | ||
19 | - <div class="info-list{{^show}} hide{{/show}}"> | ||
20 | - {{# info}} | ||
21 | - {{> guang/info}} | ||
22 | - {{/ info}} | ||
23 | - </div> | ||
24 | - {{/ infos}} | ||
25 | -</div> |
-
Please register or login to post a comment