Hello,
In a project I'm working on, I have a requirement for a component that has a go-to-top icon (or text) that appears on every page.
I'm wondering as to how this can be implemented, and if anyone has an example that has already been implemented, can you share it with me?
Thank you in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @keehwan1
Here is the example :
Component : https://github.com/arunpatidar02/aemaacs-aemlab/tree/master/ui.apps/src/main/content/jcr_root/apps/a...
component is including directly in the template structure
Context-Aware_config to control the visibility within tree/site/page :
@keehwan1 The JS , CSS code should look like something in the article.
https://www.w3schools.com/howto/howto_js_scroll_to_top.asp
For this component to show up on all pages, just add this component in your base/root page template so that all pages contain this component.
Hi @keehwan1
To implement a go-to-top component that appears on every page, you can use a combination of HTML, CSS, and JavaScript
<div id="go-to-top">
<a href="#" title="Go to top"><i class="fa fa-chevron-up"></i></a>
</div>
This creates a div
element with an id
of go-to-top
, which contains an anchor link with a font-awesome icon for the up arrow.
#go-to-top {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 9999;
}
#go-to-top a {
display: block;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
background-color: `#333`;
color: `#fff`;
border-radius: 50%;
transition: background-color 0.3s ease-in-out;
}
#go-to-top a:hover {
background-color: `#555`;
}
This styles the go-to-top component with a fixed position at the bottom right of the screen, and adds some basic styling to the link.
</body>
tagvar goToTop = document.getElementById('go-to-top');
window.onscroll = function() {
if (window.pageYOffset > 100) {
goToTop.style.display = 'block';
} else {
goToTop.style.display = 'none';
}
};
goToTop.onclick = function() {
window.scrollTo(0, 0);
};
Hi @keehwan1
Here is the example :
Component : https://github.com/arunpatidar02/aemaacs-aemlab/tree/master/ui.apps/src/main/content/jcr_root/apps/a...
component is including directly in the template structure
Context-Aware_config to control the visibility within tree/site/page :
I hope the suggestions helped you.
Requesting you to please mark the answer 'correct' that worked best for you.
Views
Likes
Replies
Views
Likes
Replies