-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
68 lines (57 loc) · 1.91 KB
/
common.js
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
$(function() {
'use strict';
function main() {
$(window).scroll(showGotoTop);
$(window).resize(showGotoTop);
$('.goto-top').click(function() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
return false;
});
initScrollspy();
showGotoTop();
showBaiduShare();
}
function initScrollspy() {
var $window = $(window);
var $body = $(document.body);
var navHeight = $('.navbar').outerHeight(true) + 10;
$body.scrollspy({
target: '.bs-sidebar',
offset: navHeight
});
$body.scrollspy('refresh');
// affix
setTimeout(function () {
var $sideBar = $('.bs-sidebar');
$sideBar.affix({
offset: {
top: function () {
var offsetTop = $sideBar.offset().top;
var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10);
var navOuterHeight = $('.bs-docs-nav').height();
return (this.top = offsetTop - navOuterHeight - sideBarMargin);
},
bottom: function () {
return (this.bottom = $('.bs-footer').outerHeight(true));
}
}
});
}, 100);
}
function showGotoTop() {
var $gotoTop = $('.goto-top'),
$bdshare = $('#bdshare');
if ($(document).scrollTop() > 0) {
$gotoTop.fadeIn('slow');
$bdshare.fadeOut('slow');
} else {
$gotoTop.fadeOut('slow');
$bdshare.fadeIn('slow');
}
}
function showBaiduShare() {
$('#bdshell_js').attr('src', 'http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000');
}
main();
});