footer.js
4.68 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
/**
* 尾部
* @author: wangqing<robin.wang@yoho.cn>
* @date: 2015/12/01
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
var $returnTop = $('.return-top');
var $qrcodeHoverBox = $('.qrcode-hover-box');
var $rightFloatingLayer = $('.right-floating-layer');
var suggestFeedBackHbs = require('hbs/common/suggest-feed-back.hbs');
var $feedBackBox = $('.feed-back-box');
lazyLoad($('img.lazy'));
// 底部友情链接动画效果
function footerLink(num) {
var n = 0;
var intv = 0;
var $linkSection = $('.footer-link-container .link-section');
if (num <= 1) {
return false;
}
function footerLinkSub() {
intv = setInterval(function() {
var top = -48 * ++n;
if (n >= num) {
n = 0;
$linkSection.css({top: 48}).animate({top: 0}, 200);
return true;
}
$linkSection.animate({top: top}, 300);
}, 3000);
}
footerLinkSub();
$linkSection.hover(function() {
clearInterval(intv);
}, function() {
footerLinkSub();
});
}
footerLink(Math.ceil($('.link-section').height() / 48));
/**
* 订阅
* @return {[type]} [description]
*/
function actionSubscription() {
var $subscriberBox = $('#subscriber-box'),
$subscriberBtn = $('#subscriber-btn'),
emailReg = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/;
var iconCode = {
mail: '',
tick: ''
};
$subscriberBox.focus(function() {
$(this).val('').css('color', '');
$subscriberBtn.removeClass('done').html(iconCode.mail);
});
$subscriberBtn.click(function() {
var email = $.trim($subscriberBox.val());
if (email !== '' && emailReg.test(email)) {
try {
$.ajax({
url: '//www.yohobuy.com/common/emailsubscriber',
dataType: 'jsonp',
data: {
email: email,
tmp: Math.random(),
uid: window.getUid()
},
success: function(data) {
if (data.data.result === 1) {
$subscriberBox.val('已订阅到:' + email);
$subscriberBtn.addClass('done').html(iconCode.tick);
} else {
$subscriberBox.css('color', 'red');
}
}
});
} catch (e) {
console.log(e.message);
}
} else {
$subscriberBox.css('color', 'red');
}
});
}
function actionhomeFootChange() {
var param = {
return_type: 'jsonp',
client_secret: 'web',
code: 200
};
// 意见反馈
$feedBackBox.on('click', '#feed-back-page span', function() {
var $this = $(this);
if ($this.hasClass('cur')) {
return;
}
$this.siblings('.cur').removeClass('cur');
$this.addClass('cur');
$feedBackBox.find('.vote').children('li').not('.hide').addClass('hide')
.end()
.eq($this.index()).removeClass('hide');
});
return $.getJSON('//www.yohobuy.com/common/suggestfeedback?callback=?', param,
function(suggestData) {
if (suggestData.code === 200 && suggestData.data.length) {
$feedBackBox.html(suggestFeedBackHbs({suggestData: suggestData.data}));
}
}
);
}
function rePosReturn() {
if ($(window).height() > $(document).height()) {
$rightFloatingLayer.addClass('hide');
}
// 只在窗口高度大于文档高度的时候,隐藏返回顶部
// else {
// $returnTop.removeClass('hide');
// }
}
// 返回顶部
$returnTop.click(function() {
$('html,body').animate({
scrollTop: 0
}, 500);
});
$qrcodeHoverBox.mouseenter(function() {
window._hmt && window._hmt.push(['_trackEvent', '二维码', '右侧悬浮', '', '']);
}).click(function() {
window._hmt && window._hmt.push(['_trackEvent', '二维码', '右侧悬浮', '', '']);
});
$(window).scroll(function() {
if ($(window).scrollTop() === 0) {
$rightFloatingLayer.addClass('hide');
} else {
$rightFloatingLayer.removeClass('hide');
}
});
// 如果初始是隐藏的,监听图片加载,重新确定return-top的高度
if ($rightFloatingLayer.hasClass('hide')) {
$('img').load(rePosReturn);
}
// 初始化
if ($('.yoho-footer .footertop').length) {
actionSubscription();
actionhomeFootChange();
}
// 暴露给有可能通AJAX改变内容的页面去用
window.rePosReturnTop = rePosReturn;