magazine.js
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* @fileOverview magazine页的JS
* @author fei.hong@yoho.cn
* @date 2014-05-30
*/
var $ = require("jquery");
var dot = require("dot");
var json = require("json");
var share = require("yoho-share");
var swiper = require('yoho.swiper');
require('../plugin/lazyloadImage');
require('../plugin/imgSlider');
require('jquery.cycle');
require('../plugin/imgZoom');
/**
* 初始化
*/
exports.init = function()
{
var shareUrl = $(".share").attr("data-link");
share.init({
shareUrl:shareUrl,
img:$(".mags-slide li").eq(0).find("img").attr("src"),
sinaText:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".date-price").find("span").text()+'期点杂志,每月7日,17日,27日出刊哦~',
fbTextFunction:function(){
return {
des:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".date-price").find("span").text()+'期点杂志,每月7日,17日,27日出刊哦~',
name:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".date-price").find("span").text()+'期点杂志,每月7日,17日,27日出刊哦~',
caption:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".date-price").find("span").text()+'期点杂志,每月7日,17日,27日出刊哦~',
url:location.href
}
},
tweetText:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".date-price").find("span").text()+'期点杂志,每月7日,17日,27日出刊哦~',
qqText:'随时引领潮流生活,我正在看《YOHO!潮流志》'+$(".date-price").find("span").text()+'期点杂志,每月7日,17日,27日出刊哦~'
});
//显示控制箭头
(function(){
var timer;
$(".column-slide").on("mouseenter",function(){
$(".column-slide").find(".slide-ctrl").hide();
if($(this).find("li").size()<=4) return;
clearTimeout(timer);
$(this).find(".slide-ctrl").show();
}).on("mouseleave",function(event){
var $that = $(this);
timer=setTimeout(function(){
$that.find(".slide-ctrl").hide();
},1000)
});
$(".column-slide .slide-ctrl").on("mouseenter",function(){
clearTimeout(timer);
$(this).show();
}).on("mouseleave",function(){
timer=setTimeout(function(){
$(this).hide();
},100)
});
})();
$("img.lazy").lazyload({
effect : "fadeIn"
});
var magazineSlide = new swiper('.mags-slide .swiper-container',{
pagination: '.slide-ctrl-tabs',
wrapperClass:'slide-piclist',
slideClass:'magazine-swiper',
paginationClickable: true,
autoplay:5000,
loop:true,
slidesPerView: 'auto',
slideElement: 'li'
})
/*var magazineSlide=new swiper('.magazine-list .swiper-container',{
//slidesPerView: 'auto',
//slideElement: 'li'
simulateTouch:false,
wrapperClass:'slide-piclist',
slideClass:'magazine',
paginationClickable: true,
slidesPerView: 'auto',
slideElement: 'li',
onSlideChangeEnd: fallSwiperItems_buy
});
function fallSwiperItems_buy(){
var currentSlide=arguments[0];
_fallSwiperItems(currentSlide,"buy");
}
function fallSwiperItems_rule(){
var currentSlide=arguments[0];
_fallSwiperItems(currentSlide,"rule");
}
var currentPageNumber=1;
function _fallSwiperItems(currentSlide,type){
var url="";
if(type=="buy") {
url="/channel/magazine/page?type=1&p=";
} else if( type=="zine") {
url="/channel/magazine/page?type=2&p=";
} else {
url="/channel/magazine/rules?p=";
}
var totalLength=$(currentSlide.container).find(".swiper-slide").length;
var currentIndex=currentSlide.activeIndex;
if(totalLength-currentIndex<=6) {
$.ajax({
url:YohoConfig.mainUrl+url+(currentPageNumber++),
cache:false,
success:function(data){
for(var i=0;i<data.data.length;i++) {
var msg=data.data;
var newAppend=currentSlide.createSlide('<li class="'+_this.options.itemClass+' swiper-slide"><a href="javascript:;"><img src="" data-slide="'+msg[i].pics+'" data-original="'+msg[i].cover+'"/><span>'+msg[i].title+'</span></a></li>');
newAppend.append();
}
var oLi=$(currentSlide.container).find(".swiper-slide");
var LastSlide = currentSlide.getLastSlide();
currentSlide.reInit();
}
});
}
}*/
/*$(".magazine-list").find(".slide-ctrl").find('.slide-ctrl-prev').on('click', function(e){
e.preventDefault();
magazineSlide.swipePrev();
});
$(".magazine-list").find(".slide-ctrl").find('.slide-ctrl-next').on('click', function(e){
e.preventDefault()
magazineSlide.swipeNext();
$(".magazine").find("img").lazyload();
});*/
/*$(".mags-slide .slide-piclist").cycle({
fx: 'scrollHorz',
speed: 300,
timeout: 5000,
pager: '.mags-slide .slide-ctrl-tabs'
});*/
$.ajax({
type:'GET',
url:'/channel/magazine/ezine',
success:function(response){
var data = response.data;
var len = data.length;
var item ='';
var ulNum = Math.ceil(len/16);
var ulItem ='';
var ulAnimateIndex = 0;
$(".mags-column .slide-box").html('<div class="slide-piclist-wrap clearfix" style="position:relative;top:0;left:0;"></div>');
//添加4个ul
for(var r=0;r<ulNum;r++){
ulItem += '<ul class="slide-piclist clearfix"></ul>';
}
$(".slide-piclist-wrap").html(ulItem);
var animateWidth = $(".mags-column").find(".slide-piclist").outerWidth();
var slideWrapWidth = animateWidth * ulNum;
$(".slide-piclist-wrap").css({"width":slideWrapWidth});
//分别插入数据到4个ul
for(var i=0;i<ulNum;i++){
var itemIndexStart = i*16;
var itemIndexEnd = i*16+16;
item = '';
if(itemIndexEnd>len){
itemIndexEnd=len;
}
for(var j = itemIndexStart;j<itemIndexEnd;j++){
item += '<li data-type='+data[j].magazineType+'><a href="javascript:;" title="'+data[j].releaseDate+'"><div class="img-wrap"><img src="'+data[j].cover+'" alt="" /></div><span>'+data[j].releaseDate+'</span></a></li>';
}
$(".slide-piclist-wrap").find(".slide-piclist").eq(i).html(item);
}
//滚动
$(".mags-column").find(".slide-ctrl-prev").hide();
$(".mags-column").on("click.next",".slide-ctrl-next",function(){
if(ulAnimateIndex>=ulNum-1) return;
if($(".slide-piclist-wrap").is(":animated")) return;
if(ulAnimateIndex==ulNum-2){
$(this).hide();
}
$(this).siblings(".slide-ctrl-prev").show();
ulAnimateIndex++;
$(".slide-piclist-wrap").stop().animate({"left":-animateWidth*ulAnimateIndex},500);
});
$(".mags-column").on("click.prev",".slide-ctrl-prev",function(){
if(ulAnimateIndex<=0) return;
if($(".slide-piclist-wrap").is(":animated")) return;
if(ulAnimateIndex==1){
$(this).hide();
}
$(this).siblings(".slide-ctrl-next").show();
ulAnimateIndex--;
$(".slide-piclist-wrap").stop().animate({"left":-animateWidth*ulAnimateIndex},500);
});
/*for(var i=0;i<len;i++){
item += '<li data-type='+data[i].magazineType+'><a href="javascript:;" title="'+data[i].releaseDate+'"><div class="img-wrap"><img src="'+data[i].cover+'" alt="" /></div><span>'+data[i].releaseDate+'</span></a></li>';
}
$(".mags-column .slide-piclist").html(item);
$(".column-slide").imgSlider();
*/
$(".mags-column .slide-piclist").find("li").each(function(){
if($(this).data("type") ==2){
$('<em class="border"></em><i class="special-icon"></i>').appendTo($(this).find(".img-wrap"));
};
});
}
})
$(".column-slide.magazine-list").imgSlider({
itemClass:'magazine'
});
$(".column-slide.rule").imgSlider();
//ipad横竖屏切换
$(window).resize(function(){
clearTimeout(timer);
var timer = setTimeout(function(){
$(".column-slide.rule").imgSlider('resize');
$(".column-slide.magazine-list").imgSlider('resize');
},0)
});
$('.column-slide.rule').ImgZoom({
imgSrcAttr:'data-imgZoom'
});
$(".slide-piclist").on("click",".magazine",function(){
if(!$(this).find("img").attr("data-slide")) return;
if($(this).find("ul").size()>=1) return;
var data = decodeURIComponent($(this).find("img").attr("data-slide"));
var arr =eval("("+data+")");
var len = arr.length;
var $picList = $('<ul style="display:none;" class="magazine-content"></ul').appendTo($(this));
var item =''
for(var i=0;i<len;i++){
item += '<li><img src="" data-imgzoom="'+arr[i]+'" alt="" /></li>';
}
$(item).appendTo($picList);
$(this).ImgZoom({
isContainFather: true
});
});
$(".column-slide.rule").on("mouseenter","li",function(){
var gifSrc = $(this).find("img").attr("data-imgzoom");
$(this).find("img").attr("src",gifSrc);
}).on("mouseleave","li",function(){
var staticSrc = $(this).find("img").attr("data-original");
$(this).find("img").attr("src",staticSrc);
})
}