return-top.js
1.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
/**
* [公共底部]返回页面顶部
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/07/05
*/
var $ = require('yoho-jquery');
var $returnTop = $('.return-top');
/**
* 是否显示返回顶部按钮
*/
function showOrNot() {
if ($(window).height() >= $(document).height()) {
$returnTop.addClass('hide');
}
}
function reposReturnTop() {
var $top = $returnTop.parent();
if (!$top.hasClass('service-top')) {
$top = $returnTop;
}
if ($(window).width() < 1380) {
$top.addClass('for-min');
} else {
$top.removeClass('for-min');
}
}
$returnTop.click(function() {
$('html,body').animate({
scrollTop: 0
}, 500);
});
$(window).scroll(function() {
if ($(window).scrollTop() === 0) {
$returnTop.addClass('hide');
} else {
$returnTop.removeClass('hide');
}
});
// 页面图片加载完成后根据页面高度决定是否显示
if ($returnTop.hasClass('hide')) {
$('img').load(showOrNot);
}
reposReturnTop();
if ($returnTop.length) {
$(window).resize(reposReturnTop);
}
exports.returnTopShowOrNot = showOrNot;