Skip to content

Commit

Permalink
hover no fade
Browse files Browse the repository at this point in the history
  • Loading branch information
justinh-rahb committed Oct 21, 2023
1 parent a1960b3 commit 6238b79
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@
<p>The trademarks REALTOR®, REALTORS®, and the REALTOR® logo are controlled by <a href="https://www.crea.ca" target="_blank">The Canadian Real Estate Association</a> (CREA) and identify real estate professionals who are members of CREA.</p>
<p>Data Copyright © 2023 <a href="https://www.rahb.ca" target="_blank">REALTORS® Association of Hamilton-Burlington</a> with portions Copyright © 2023 <a href="https://www.reso.org" target="_blank">RESO</a>.</p>
</footer>
<script src="static/viewer.js?v=202310211013"></script>
<script src="static/viewer.js?v=202310211021"></script>
</body>
</html>
29 changes: 23 additions & 6 deletions static/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ document.getElementById('downloadLink').addEventListener('click', function() {

// Scroll to top button
let timeout;
let isHovered = false; // flag to check if the button is being hovered over

const scrollToTopButton = document.getElementById("scrollToTopButton");

function showButton() {
Expand All @@ -184,21 +186,36 @@ function showButton() {
}

function hideButton() {
scrollToTopButton.classList.remove('fade-in');
scrollToTopButton.classList.add('fade-out');
setTimeout(() => {
scrollToTopButton.style.display = 'none';
}, 500); // match this with your CSS transition time
if (!isHovered) {
scrollToTopButton.classList.remove('fade-in');
scrollToTopButton.classList.add('fade-out');
setTimeout(() => {
if (!isHovered) {
scrollToTopButton.style.display = 'none';
}
}, 500); // match this with your CSS transition time
}
}

window.addEventListener('scroll', function() {
if (window.scrollY > 200) {
showButton();
clearTimeout(timeout);
timeout = setTimeout(hideButton, 2000); // 2 seconds
timeout = setTimeout(hideButton, 3000); // 3 seconds
}
});

// Handle hover state
scrollToTopButton.addEventListener('mouseenter', function() {
isHovered = true;
});

scrollToTopButton.addEventListener('mouseleave', function() {
isHovered = false;
hideButton();
});

// Scroll to top on click
scrollToTopButton.addEventListener('click', function() {
window.scrollTo({
top: 0,
Expand Down

0 comments on commit 6238b79

Please sign in to comment.