plustar-list.page.js
1.66 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
require('guang/plustar-list.page.css');
let $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
Swiper = require('yoho-swiper');
let $navs = $('#nav-tab > li'),
$contents = $('#ps-content > .content');
require('common');
lazyLoad($('img.lazy'));
$('#nav-tab').bind('contextmenu', function() {
return false;
});
$('#nav-tab').on('touchend touchcancel', function(e) {
let $this = $(e.target).closest('li');
if ($this.hasClass('focus')) {
return;
}
$navs.removeClass('focus');
$this.addClass('focus');
$contents.addClass('hide');
$contents.eq($this.index()).removeClass('hide');
if (typeof $this.swiper === 'undefined') { // 解决隐藏式,swiper不渲染
$this.swiper = false;
$contents.find('li').each(function(key, item) {
$(item).find('.swiper-container').addClass('swiper-' + key);
if (!$(item).swiper) {
$(item).swiper = true;
new Swiper('.swiper-' + key, {
lazyLoading: true,
pagination: '.swiper-' + key + ' .pagination-inner'
});
}
});
}
$(document).trigger('scroll'); // Trigger lazyLoad
});
// if ($('#nav-tab').find('li:eq(0)').hasClass('focus')) {
// // 解决li隐藏 swiper不渲染的问题
// $('#nav-tab').find('li:eq(0)').removeClass('focus');
// $('#nav-tab').find('li:eq(0)').trigger('touchend');
// }
$('#nav-tab').on('touchstart', function(e) {
let target = e.target || e.srcElement;
target.className = 'bytouch ' + target.className;
}).on('touchend touchcancel', function() {
$navs.removeClass('bytouch');
});