From 990daceed5cc051acaf1b45094c541e5c56d9306 Mon Sep 17 00:00:00 2001 From: Sorin Davidoi Date: Fri, 9 Feb 2018 11:34:18 +0100 Subject: [PATCH] feat(theme/book): Scroll to top when clicking the page title (#613) Common pattern, especially on mobile devices where the page can be quite long. --- src/theme/book.css | 1 + src/theme/book.js | 8 ++++++++ src/theme/stylus/menu.styl | 1 + 3 files changed, 10 insertions(+) diff --git a/src/theme/book.css b/src/theme/book.css index 80160288..1efbfb85 100644 --- a/src/theme/book.css +++ b/src/theme/book.css @@ -220,6 +220,7 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta overflow: hidden; -o-text-overflow: ellipsis; text-overflow: ellipsis; + cursor: pointer; } .nav-chapters { font-size: 2.5em; diff --git a/src/theme/book.js b/src/theme/book.js index 489d994a..53806af0 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -522,6 +522,14 @@ function playpen_text(playpen) { }); })(); +(function scrollToTop () { + var menuTitle = document.querySelector('.menu-title'); + + menuTitle.addEventListener('click', function () { + document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' }); + }); +})(); + (function autoHideMenu() { var menu = document.getElementById('menu-bar'); diff --git a/src/theme/stylus/menu.styl b/src/theme/stylus/menu.styl index eae9469a..e50987b5 100644 --- a/src/theme/stylus/menu.styl +++ b/src/theme/stylus/menu.styl @@ -38,4 +38,5 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta white-space: nowrap overflow: hidden text-overflow: ellipsis + cursor: pointer; }