Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init Back to top #585

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
5 changes: 4 additions & 1 deletion src/components/bs5/backToTop/backToTop.data.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"hide_back_to_top": false
"hide_back_to_top": false,
"text":"Back to top",
"dynamic":false,
"offset": 100
}
26 changes: 19 additions & 7 deletions src/components/bs5/backToTop/backToTop.functions.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
export function backToTop() {
// Get the Back To Top object:
// The offset is the number of pixels after which the button is displayed
// The dynamic attribute is used to determine if the buttons CSS uses Relitive or Fixed positioning

let mybutton = document.getElementById("backToTop");
let btnIsDynamic = mybutton.getAttribute("data-dynamic");

mybutton.addEventListener("click", goToTop);

// When the user scrolls down 30px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
if (btnIsDynamic == "true") {
mybutton.classList.remove("show");
window.onscroll = function() {scrollFunction()};
}

function scrollFunction() {
if (document.body.scrollTop > 30 || document.documentElement.scrollTop > 30) {
mybutton.classList.add("show");
mybutton.addEventListener("click", goToTop)
} else {
mybutton.classList.remove("show");
if (btnIsDynamic == "true") {
let offset = mybutton.getAttribute("data-offset");
if (document.body.scrollTop > offset || document.documentElement.scrollTop > offset) {
mybutton.classList.add("show");
mybutton.setAttribute("aria-hidden", false);
} else {
mybutton.classList.remove("show");
mybutton.setAttribute("aria-hidden", true);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/bs5/backToTop/backToTop.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#unless hide_back_to_top}}
<div class="qld__widgets">
<a href="#" id="backToTop" class="qld__btn qld__btn--floating qld__btn--back-to-top" aria-label="Back to top">
<span>Back to top</span>
<div class="qld__widgets {{#if dynamic}}fixed{{/if}}">
<a href="#" id="backToTop" class="qld__btn qld__btn--floating qld__btn--back-to-top show" data-offset="{{offset}}" data-dynamic="{{dynamic}}" aria-label="{{text}}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have 'default' if 'text' is not set, i.e. 'Back to top'
offset default should be '100'.
Also why is dynamic when true == fix.
and data-dynamic default if not set is 'false'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These issues are now fixed with the latest push

<span>{{text}}</span>
</a>
</div>
{{/unless}}
15 changes: 10 additions & 5 deletions src/components/bs5/backToTop/backToTop.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
//--------------------------------------------------------------------------------------------------------------------------------------------------------------

.qld__widgets {
bottom:0.75rem;
right: 0.75rem;
align-items: flex-end;
display: flex;
align-items: flex-end;
flex-direction: column;
position: fixed;
position: relative;
z-index: 1;

&.fixed {
position: fixed;
bottom:0.75rem;
right: 0.75rem;
z-index: 10;
}

.qld__btn--floating {
display: inline-block;
}

}

.qld__widgets + .qld__footer {
Expand Down
Loading