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

add go to top button #148

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,35 @@ img {
background-color: lightgreen;
color: darkgreen;
}

#myBtn {
position: fixed; /* Fixed/sticky position */
bottom: 120px; /* Place the button at the bottom of the page */
right: 40px; /* Place the button 30px from the right */
z-index: 99; /* Make sure it does not overlap */
border: none; /* Remove borders */
outline: none; /* Remove outline */
background-color: #26eab9; /* Set a background color */
color: BLACK; /* Text color */
cursor: pointer; /* Add a mouse pointer on hover */
padding: 1px 7px; /* Some padding */
border-radius: 25%; /* Rounded corners */
font-size: 18px; /* Increase font size */
font-weight: 400;
}

#myBtn:hover {
background-color: darkgreen; /* Add a dark-grey background on hover */
color: white;
}
@media only screen and (max-width: 600px) {
#myBtn {
font-size: 30px;
border-radius: 100px;
width: 55px;
}

#myBtn:hover {
background-color: white; /* Add a dark-grey background on hover */
}
}
20 changes: 20 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
Z;
let mybutton = document.getElementById("myBtn");

// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function () {
scrollFunction();
};

function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}

// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@
<!-- Title -->

<title>CALCULATOR | YOSHITHA</title>
<script src="assets\js\app.js"></script>
</head>

<body class="bg-img">
<button onclick="topFunction()" id="myBtn" title="Go to top">⇮</button>
<header class="text-center title"><b>CALCULATOR</b></header>

<center>
Expand Down