Skip to content

Commit

Permalink
Fix back-to-top button and remove some scroll jank.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 28, 2016
1 parent d7994b9 commit 027ded8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions themes/cakephp/static/app.js
Expand Up @@ -16,16 +16,18 @@ App.Book = (function() {
doc = $(document),
offset = contents.offset(),
sidebarHeight = contents.height(),
delay = 150,
didScroll = false;
showing = false;

var positionBackToTop = function() {
setTimeout(positionBackToTop, delay);
if (offset === undefined) {
return;
}
if (!showing && doc.scrollTop() > offset.top + sidebarHeight) {
showing = true;
backToTop.css({
position: 'fixed',
top: 50,
left: 20,
display:' block'
Expand All @@ -37,14 +39,15 @@ App.Book = (function() {
});
}
};
setTimeout(positionBackToTop, delay);

backToTop.bind('click', function(evt) {
$('html,body').animate({scrollTop: offset.top}, 200);
$('html,body').animate({scrollTop: 0}, 200);
return false;
});

doc.bind('scroll', function() {
positionBackToTop();
didScroll = true;
});

// Tooltips
Expand Down
10 changes: 9 additions & 1 deletion themes/cakephp/static/css/default.css
Expand Up @@ -146,13 +146,21 @@ dl.docutils {
cursor: pointer;
}

/* -- back to top -- */
#back-to-contents {
display: block;
position: fixed;
background: #fff;
}
/* -- Page Contents -- */
.page-contents {
background: rgba(189, 189, 181, 0.32);
background: #eaeae7;
float: right;
padding: 2em;
margin-left: 2em;
margin-bottom: 1em;
position: relative;
z-index: 1;
}
.page-contents h3 {
font-size: 1em;
Expand Down

0 comments on commit 027ded8

Please sign in to comment.