/
plugin.js
32 lines (28 loc) · 1020 Bytes
/
plugin.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
require([
'gitbook',
'jquery'
], function(gitbook, $) {
gitbook.events.on('page.change', function() {
var back_to_top_button = ['<div class="back-to-top"><i class="fa fa-arrow-up"></i></div>'].join("");
$(".page-wrapper").append(back_to_top_button)
$(".back-to-top").hide();
$(".back-to-top").hover(function() {
$(this).css('cursor', 'pointer').attr('title', 'Back to top');
}, function() {
$(this).css('cursor', 'auto');
});
$('.book-body,.body-inner,.page-wrapper').on('scroll', function () {
if ($(this).scrollTop() > 100) {
$('.back-to-top').fadeIn();
} else {
$('.back-to-top').fadeOut();
}
});
$('.back-to-top').on('click', function () {
$('.book-body,.body-inner').animate({
scrollTop: 0
}, 800);
return false;
});
});
});