plusstar-index.page.js
4.05 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
var $ = require('yoho-jquery'),
tip = require('../plugin/tip'),
Swiper = require('yoho-swiper'),
loading = require('../plugin/loading'),
lazyLoad = require('yoho-jquery-lazyload');
var plusstar = {},
$footer = $('#yoho-footer');
require('../common');
plusstar = {
common: {
codeDefault: ''
},
init: function() {
var that = this,
$liDom,
$tabUlDom;
$tabUlDom = $('.plusstar-page .tab-nav ul');
// 重置tab code位置
if (window.localStorage) {
$tabUlDom.find('li').each(function() {
localStorage.setItem($(this).data('code'), 0);
});
}
$tabUlDom.find('li').css({
width: 100 / $tabUlDom.find('li').length + '%'
});
// 事情委托机制
$tabUlDom.bind('click', function(event) {
$liDom = $(event.target).closest('li');
if ($liDom.hasClass('focus')) {
return true;
}
$(this).find('li').removeClass('focus');
$liDom.addClass('focus');
that.tabNav($liDom.data('code'));
});
// start -- 默认选中
$liDom = $tabUlDom.find('li.focus');
if ($liDom.length <= 0) {
// 默认第一个
$liDom = $('.plusstar-page .tab-nav ul li:eq(0)');
}
$tabUlDom.find('li').removeClass('focus');
$liDom.addClass('focus');
that.tabNav($liDom.data('code'));
// ent -- 默认选中
},
tabNav: function(code) {
var that = this;
this.common.codeDefault = code;// 记住最后一次的tab code
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: '/guang/plusstar/resources-template',
data: {
code: code,
app_version: window.queryString.app_version || window.queryString.appVersion
},
dataType: 'html',
success: function(data) {
$('.plusstar-resources').html(data);
if (data === '') {
tip.show('没有更多内容了');
return true;
}
that.resInit();
loading.hideLoadingMask();
lazyLoad($('img.lazy'));
// 处理左右滑动,未加载的图片
setTimeout(function() {
$('img.lazy').each(function() {
if ($(this).attr('src') !== $(this).data('original')) {
$(this).attr('src', $(this).data('original'));
}
});
}, 40);
// 设置滚动条的位置
if (window.localStorage) {
$(document).scrollTop(localStorage.getItem(code) || 0);
}
},
error: function() {
tip.show('网络断开连接了~');
loading.hideLoadingMask();
}
});
},
resInit: function() {
// 头部banner轮播
if ($('.banner-swiper').find('li').size() > 1) {
new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.banner-top .pagination-inner'
});
}
}
};
$(function() {
if (!(window.queryString.app_version || window.queryString.appVersion)) {
$('.tab-nav').css({
position: 'absolute'
});
$footer.css({
'max-width': '650px'
}).before(
'<div style="height: ' + parseInt($footer.css('height'), 0) + 'px"></div>'
);
}
plusstar.init();
if (window.localStorage) {
$(document).scroll(function() {
localStorage.setItem(plusstar.common.codeDefault, $(this).scrollTop());
});
}
});