new-home.page.js
3.82 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
import 'home/new-home.page.css';
import 'product/new-recommend/new-recommend';
import $ from 'yoho-jquery';
import Page from 'yoho-page';
import 'common/set-trend-world';
import Swiper from 'yoho-swiper2';
import yoho from 'yoho-app';
import AutoScroll from './new-home/auto-scroll';
class NewHome extends Page {
constructor() {
super();
this.selector = {
$userAvatar: $('.user-avatar'),
$codeSet: $('.code-set'),
$resYas: $('.res-c').find('a'),
$trendCode: $('.trend-code'),
$floatTop: $('.float-top'),
$recommendC: $('#new-recommend-c')
};
this.init();
}
init() {
this.defaultPic();
this.bindEvents();
this.swiper();
this.showTrend();
this.autoScroll();
this.backToTop();
window.reMarginFooter('.footer-tab');
}
backToTop() {
if (this.selector.$recommendC.length > 0) {
$(document).scroll(() => {
let recommendTop = this.selector.$recommendC.offset().top - $(document).scrollTop();
if (recommendTop <= 400) {
this.selector.$floatTop.addClass('hover');
} else {
this.selector.$floatTop.removeClass('hover');
}
});
}
}
autoScroll() {
new AutoScroll(
{
scrollC: $('.scroll-c'), // 内容
scrollWords: $('.scroll-words') // 容器
}
);
}
// 首次进入个人中心,且登陆,且没有设置潮流口令,打开弹框子
showTrend() {
if (yoho.isLogin() && (!this.selector.$trendCode.hasClass('trend')) && !window.cookie('first-trend')) {
$('.set-trend-world').removeClass('set-trend-hide');
window.setCookie('first-trend', true, {
path: '/home',
expires: 1
});
}
}
bindEvents() {
this.selector.$codeSet.on('click', this.codeSet.bind(this));
this.selector.$resYas.on('click', this.yas.bind(this));
}
// 资源位
swiper() {
if ($('.banner-center-swiper').length > 0) {
new Swiper('.banner-center-swiper', {
pagination: '.swiper-pagination',
lazyLoading: true,
lazyLoadingInPrevNext: true,
paginationClickable: true,
autoplay: 3000
});
}
}
// 埋点
yas(e) {
let $this = $(e.currentTarget);
let index = $this.index() + 1;
let pIndex = $this.parent('div').index() + 1;
let url = $this.attr('href');
let name = $this.attr('name');
let id = $this.attr('id');
let status = $this.parent('li').hasClass('swiper-slide');
if (status) {
index = $this.parent('li').index() + 1;
pIndex = 1;
}
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo && window._yas.sendCustomInfo({
op: 'YB_MY_BANNER_C',
param: JSON.stringify({
I_INDEX: index,
F_URL: encodeURIComponent(url),
F_NAME: name,
F_INDEX: pIndex,
F_ID: id
})
}, true);
}
}
// 默认头像
defaultPic() {
let myImage = new Image(),
avatar;
avatar = this.selector.$userAvatar.data('avatar') || '';
myImage.src = avatar;
myImage.onload = () => {
this.selector.$userAvatar.css('background-image', 'url(' + avatar + ')');
};
}
// 修改潮流口令
codeSet(e) {
e.preventDefault();
$('.set-trend-world').show();
return false;
}
}
$(() => {
new NewHome();
});