Skip to content

Commit bf31f3e

Browse files
authored
Merge pull request #2243 from kazuhitonakayama/add-button-for-scrolling-to-top
Place a scrollable button to the top of the page
2 parents 6f46483 + e0bf94a commit bf31f3e

6 files changed

Lines changed: 47 additions & 0 deletions

File tree

includes/scroll-button.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<button class="arrow-for-scrolling-top" id="js-scroll-top">
2+
{% octicon "chevron-up" %}
3+
</button>

javascripts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import '../stylesheets/index.scss'
33
import displayPlatformSpecificContent from './display-platform-specific-content'
44
import explorer from './explorer'
5+
import scrollUp from './scroll-up'
56
import search from './search'
67
import nav from './nav'
78
import browserDateFormatter from 'browser-date-formatter'
@@ -23,6 +24,7 @@ import airgapLinks from './airgap-links'
2324
document.addEventListener('DOMContentLoaded', async () => {
2425
displayPlatformSpecificContent()
2526
explorer()
27+
scrollUp()
2628
search()
2729
nav()
2830
browserDateFormatter()

javascripts/scroll-up.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default function () {
2+
// function to scroll up to page top
3+
const PageTopBtn = document.getElementById('js-scroll-top')
4+
if (!PageTopBtn) return
5+
6+
PageTopBtn.addEventListener('click', (e) => {
7+
window.scrollTo({
8+
top: 0,
9+
behavior: 'smooth'
10+
})
11+
})
12+
13+
// show scroll button only when display is scroll down
14+
window.addEventListener('scroll', function () {
15+
const y = document.documentElement.scrollTop // get the height from page top
16+
if (y < 100) {
17+
PageTopBtn.classList.remove('show')
18+
} else if (y >= 100) {
19+
PageTopBtn.classList.add('show')
20+
}
21+
})
22+
}

layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{% endif %}
1616
{% include support-section %}
1717
{% include small-footer %}
18+
{% include scroll-button %}
1819
</main>
1920
</body>
2021
</html>

stylesheets/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ $marketing-font-path: "/dist/fonts/";
4747
@import "search.scss";
4848
@import "overrides.scss";
4949
@import "sidebar.scss";
50+
@import "scroll-button.scss";
5051
@import "explorer.scss";
5152
// from https://unpkg.com/highlight.js@9.15.8/styles/github.css
5253
@import "syntax-highlighting.scss";

stylesheets/scroll-button.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
button.arrow-for-scrolling-top {
2+
opacity: 0;
3+
transition: 1s;
4+
background-color: #0367d6;
5+
color: #fff;
6+
position: fixed;
7+
bottom: 10px;
8+
right: 10px;
9+
display: block;
10+
width: 40px;
11+
height: 40px;
12+
border-radius: 50%;
13+
&.show {
14+
opacity: 1;
15+
border: none;
16+
transition: 1s;
17+
}
18+
}

0 commit comments

Comments
 (0)