Merge pull request #48354 from ally1002/guide-back-to-top

Adding the button using JS and styling with CSS and Image [ #48277 ]
This commit is contained in:
Guillermo Iguaran 2023-06-01 00:38:41 -07:00 committed by GitHub
commit d026af43c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 0 deletions

@ -1 +1,5 @@
* Add "back to top" button to guides
*Alysson Rosa*
Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/guides/CHANGELOG.md) for previous changes.

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

@ -44,6 +44,26 @@
}
});
var backToTop = createElement("a", "back-to-top");
backToTop.setAttribute("href", "#");
document.body.appendChild(backToTop);
backToTop.addEventListener("click", function(e) {
e.preventDefault();
window.scrollTo({ top: 0, behavior: "smooth" });
});
var toggleBackToTop = function() {
if (window.scrollY > 300) {
backToTop.classList.add("show");
} else {
backToTop.classList.remove("show");
}
}
document.addEventListener("scroll", toggleBackToTop);
var guidesIndexItem = document.querySelector("select.guides-index-item");
var currentGuidePath = window.location.pathname;
guidesIndexItem.value = currentGuidePath.substring(currentGuidePath.lastIndexOf("/") + 1) || 'index.html';

@ -264,6 +264,22 @@ body {
background: #ccc;
}
a.back-to-top {
visibility: hidden;
position: fixed;
right: 1em;
bottom: 1em;
padding: 2.5em;
border-radius: 3em;
box-shadow: 2px 2px 4px 0px black;
background: url('../images/up-white-arrow.png') no-repeat center center, #c52f24;
background-size: 2em;
}
a.back-to-top.show {
visibility: visible;
}
#header {
background: #c52f24 url(../images/header_tile.gif) repeat-x;
color: #FFF;