Skip to content

Commit

Permalink
feat: create a button top
Browse files Browse the repository at this point in the history
  • Loading branch information
esterfania committed Oct 22, 2024
1 parent b094b87 commit d46e292
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
14 changes: 14 additions & 0 deletions assets/css/button_up.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/button_up.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions assets/js/scrollToTop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const button = document.querySelector(".button-up");

const showButtonIfScroll = () => {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
button.style.display = "block";
} else {
button.style.display = "none";
}
};

const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
};

button.addEventListener("click", scrollToTop);
window.onscroll = () => showButtonIfScroll();
13 changes: 13 additions & 0 deletions assets/sass/button_up.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import "variables"

.button-up
background-color: $primary-500
color: $white
border: none
border-radius: 5px
padding: 10px 20px
cursor: pointer
position: fixed
top: 90%
right: 20px
display: none
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/button_up.css" />

<!-- Phosphor Icons -->
<script src="https://unpkg.com/@phosphor-icons/web"></script>
Expand Down Expand Up @@ -83,9 +84,14 @@ <h2 class="header__subtitle">
</div>
</div>
</div>
<button class="button-up">
Up
<i class="ph ph-arrow-up"></i>
</button>
</main>
<script src="assets/js/script.js" type="module"></script>
<script src="assets/js/cookies.js" type="module"></script>
<script src="assets/js/scrollToTop.js" type="module"></script>
</body>

</html>
</html>

0 comments on commit d46e292

Please sign in to comment.