Skip to content

Commit 4dd4be2

Browse files
committed
adding button to scroll to top
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent 9635249 commit 4dd4be2

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dockerhub: vanessa
4242
# logo: "assets/img/logo/SRCC-square-white.png"
4343
logo: "assets/img/logo/SRCC-square-red.png"
4444
logo_pixels: 34
45+
color: "#8c1515" # primary color for header, buttons
4546

4647
# Build settings
4748
markdown: kramdown

_includes/scrolltop.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<style>
2+
#scrolltop {
3+
display: none; /* Hidden by default */
4+
position: fixed; /* Fixed/sticky position */
5+
bottom: 20px; /* Place the button at the bottom of the page */
6+
right: 30px; /* Place the button 30px from the right */
7+
z-index: 99; /* Make sure it does not overlap */
8+
border: none; /* Remove borders */
9+
outline: none; /* Remove outline */
10+
background-color: {{ site.color }}; /* Set a background color */
11+
color: white; /* Text color */
12+
cursor: pointer; /* Add a mouse pointer on hover */
13+
padding: 10px 15px; /* Some padding */
14+
border-radius: 100px; /* Rounded corners */
15+
font-size: 18px; /* Increase font size */
16+
font-weight: 600;
17+
}
18+
19+
#scrolltop:hover {
20+
background-color: #555; /* Add a dark-grey background on hover */
21+
}
22+
</style>
23+
<button onclick="topFunction()" id="scrolltop" title="Go to top">^</button>
24+
25+
<script>
26+
// When the user scrolls down 20px from the top of the document, show the button
27+
window.onscroll = function() {scrollFunction()};
28+
29+
function scrollFunction() {
30+
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
31+
document.getElementById("scrolltop").style.display = "block";
32+
} else {
33+
document.getElementById("scrolltop").style.display = "none";
34+
}
35+
}
36+
37+
// When the user clicks on the button, scroll to the top of the document
38+
function topFunction() {
39+
document.body.scrollTop = 0; // For Safari
40+
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
41+
}
42+
</script>

_layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
</main>
1717
</div>
1818
{% include footer.html %}
19+
{% include scrolltop.html %}
1920
</body>
2021
</html>

assets/css/palette.css

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
layout: null
3+
excluded_in_search: true
4+
---
15
button[data-md-color-accent], button[data-md-color-primary] {
26
width: 13rem;
37
margin-bottom: .4rem;
@@ -13,16 +17,16 @@ button[data-md-color-accent]:hover, button[data-md-color-primary]:hover {
1317
opacity: .75;
1418
}
1519
button[data-md-color-primary=red] {
16-
background-color: #8c1515;
20+
background-color: {{ site.color }};
1721
}
1822
[data-md-color-primary=red] .md-typeset a {
19-
color: #8c1515;
23+
color: {{ site.color }};
2024
}
2125
[data-md-color-primary=red] .md-header, [data-md-color-primary=red] .md-hero {
22-
background-color: #8c1515;
26+
background-color: {{ site.color }};
2327
}
2428
[data-md-color-primary=red] .md-nav__link--active, [data-md-color-primary=red] .md-nav__link:active {
25-
color: #8c1515;
29+
color: {{ site.color }};
2630
}
2731
[data-md-color-primary=red] .md-nav__item--nested>.md-nav__link {
2832
color: inherit;
@@ -756,7 +760,7 @@ button[data-md-color-accent=deep-orange] {
756760
}
757761
@media only screen and (max-width:76.1875em) {
758762
html [data-md-color-primary=red] .md-nav--primary .md-nav__title--site {
759-
background-color: #8c1515;
763+
background-color: {{ site.color }};
760764
}
761765
html [data-md-color-primary=pink] .md-nav--primary .md-nav__title--site {
762766
background-color: #e91e63;
@@ -822,7 +826,7 @@ html [data-md-color-primary=white] .md-nav--primary .md-nav__title--site {
822826
}
823827
@media only screen and (min-width:76.25em) {
824828
[data-md-color-primary=red] .md-tabs {
825-
background-color: #8c1515;
829+
background-color: {{ site.color }};
826830
}
827831
[data-md-color-primary=pink] .md-tabs {
828832
background-color: #e91e63;

0 commit comments

Comments
 (0)