Skip to content

Commit

Permalink
back to top button
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvijaysingh committed Feb 15, 2024
1 parent 5c53a46 commit 4239b38
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
17 changes: 17 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,20 @@ a:hover{
background-clip: text;
-webkit-text-fill-color: transparent;
}

/*--------- Back To Top ------------*/

#backToTopButton{
display: none;
position: fixed;
right: 10px;
bottom: 0px;
z-index: 999;
transition: var(--transition-default);
}


#backToTopButton:hover{
color: var(--primary-color);
transform: translate(0, -0.25rem) rotate(0) skewX(0) skewY(0) scaleX(1) scaleY(1);
}
22 changes: 19 additions & 3 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ if (switchThemeBtn) {
});
}

// Fixed Header on Scroll
//AOS Initiliaze
AOS.init();

// Fixed Header & back to top button on Scroll
window.addEventListener('scroll', () => {
// fixed header
const header = document.getElementById('header');
if (window.scrollY > 30 && !header.classList.contains('fixed-top')) {
header.classList.add('fixed-top');
Expand All @@ -31,10 +35,22 @@ window.addEventListener('scroll', () => {
header.classList.remove('fixed-top');
document.getElementById('offcanvasNavbar').classList.remove('fixedHeaderNavbar');
}

//backtotop
const backToTopButton = document.getElementById("backToTopButton");
if (window.scrollY > 400 && backToTopButton.style.display === 'none') {
backToTopButton.style.display = 'block';
} else if (window.scrollY <= 400 && backToTopButton.style.display === 'block') {
backToTopButton.style.display = 'none';
}
});

//AOS Initiliaze
AOS.init();

//jumping to top function
function scrollToTop(){
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}

//Testimonial Slider
$(document).ready(function(){
Expand Down
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,14 @@ <h2 class="section-heading text-center">Get In Touch</h2>
</div>
</footer>

<button class="btn" id="backToTopButton" onclick="scrollToTop()" style="display: none;">
<span aria-label="Back to top">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-arrow-up-square" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M15 2a1 1 0 0 0-1-1H2a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1zM0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm8.5 9.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707z"/>
</svg>
</span>
</button>

<!-- JavaScript -->
<script src="https://unpkg.com/[email protected]/dist/aos.js" defer></script>
<script src="assets/js/jquery-3.7.1.min.js" defer></script>
Expand Down

0 comments on commit 4239b38

Please sign in to comment.