Authored by yyqing

swiper初始化机制调整

... ... @@ -4,8 +4,7 @@
* @date: 2015/10/10
*/
var $ = require('jquery'),
Swiper = require('yoho.iswiper');
var $ = require('jquery');
var info = require('./info'),
loadMore = info.loadMore;
... ... @@ -24,18 +23,12 @@ var $infoList = $('#info-list'),
var state = {};
var mySwiper;
if ($loadMoreInfo.length > 0) {
$loading = $loadMoreInfo.children('.loading');
$noMore = $loadMoreInfo.children('.no-more');
}
mySwiper = new Swiper('.swiper-container', {
lazyLoading: true,
pagination: '.swiper-pagination',
autoplay: 3000
});
info.initSwiper(curType);
info.initInfosEvt($infoList);
... ...
... ... @@ -7,16 +7,19 @@
var $ = require('jquery'),
Hammer = require('yoho.hammer'),
ellipsis = require('mlellipsis'),
lazyLoad = require('yoho.lazyload');
lazyLoad = require('yoho.lazyload'),
Swiper = require('yoho.iswiper');
var tip = require('../plugin/tip');
var loading = require('../plugin/loading');
var $loadMoreInfo = $('#load-more-info');
var $loading = $(''),
$noMore = $('');
$noMore = $(''),
$swiper = $('');
var searching = false;
var mySwiper = {};
ellipsis.init();
... ... @@ -25,6 +28,20 @@ if ($loadMoreInfo.length > 0) {
$noMore = $loadMoreInfo.children('.no-more');
}
//初始化swiper
function initSwiper(typeId) {
console.log(typeId);
if (typeof typeId === undefined) {
return;
}
mySwiper[typeId] = new Swiper('.swiper-cont-' + typeId, {
lazyLoading: true,
wrapperClass: 'swiper-wrap-' + typeId,
pagination: '.swiper-pagi-' + typeId,
autoplay: 3000
});
}
/**
* 设置指定资讯项的Lazyload和文字截取
* @params $infos 资讯项
... ... @@ -175,6 +192,14 @@ function loadMore($container, opt, url) {
$container.append(data);
$swiper = $container.find('.swiper-container');
if ($swiper.length) {
$swiper.addClass('swiper-cont-' + opt.type);
$swiper.children('.swiper-wrapper').addClass('swiper-wrap-' + opt.type);
$swiper.children('.swiper-pagination').addClass('swiper-pagi-' + opt.type);
initSwiper(opt.type);
}
if (num > 0) {
$newItems = $container.find('.guang-info:gt(' + (num - 1) + ')');
} else {
... ... @@ -202,6 +227,9 @@ function loadMore($container, opt, url) {
});
}
exports.mySwiper = mySwiper;
exports.initSwiper = initSwiper;
exports.initInfosEvt = initInfosEvt;
exports.setLazyLoadAndMellipsis = setLazyLoadAndMellipsis;
exports.loadMore = loadMore;
\ No newline at end of file
... ...
... ... @@ -9,8 +9,32 @@
</li>
{{/ navs}}
</ul>
<div class="guang-item-content">
{{> guang/home}}
<div id="info-list" class="info-list-container">
{{# infos}}
<div class="info-list{{^show}} hide{{/show}}">
{{#if show}}
{{#if ../swiper}}
<div class="swiper-container swiper-cont-{{@index}}">
<div class="swiper-wrapper swiper-wrap-{{@index}}">
{{# swiper}}
<div class="swiper-slide">
<a href="{{url}}">
<img class="swiper-lazy" data-src="{{img}}">
</a>
<div class="swiper-lazy-preloader"></div>
</div>
{{/ swiper}}
</div>
<div class="swiper-pagination swiper-pagi-{{@index}}"></div>
</div>
{{/if}}
{{/if}}
{{# info}}
{{> guang/info}}
{{/ info}}
</div>
{{/ infos}}
</div>
<div id="load-more-info" class="load-more-info">
... ...
{{#if swiper}}
<div class="swiper-container">
<div class="swiper-wrapper">
{{# swiper}}
<div class="swiper-slide">
<a href="{{url}}">
<img class="swiper-lazy" data-src="{{img}}">
</a>
<div class="swiper-lazy-preloader"></div>
</div>
{{/ swiper}}
</div>
<div class="swiper-pagination"></div>
</div>
{{/if}}
{{# infos}}
{{> guang/info}}
{{/ infos}}
\ No newline at end of file
... ...
{{#if swiper}}
<div class="swiper-container">
<div class="swiper-wrapper">
{{# swiper}}
<div class="swiper-slide">
<a href="{{url}}">
<img class="swiper-lazy" data-src="{{img}}">
</a>
<div class="swiper-lazy-preloader"></div>
</div>
{{/ swiper}}
</div>
<div class="swiper-pagination"></div>
</div>
{{/if}}
<div id="info-list" class="info-list-container">
{{# infos}}
<div class="info-list{{^show}} hide{{/show}}">
{{# info}}
{{> guang/info}}
{{/ info}}
</div>
{{/ infos}}
</div>
\ No newline at end of file