rework to up button

This commit is contained in:
mrilyew 2024-11-02 13:02:34 +03:00
parent 389f0b4bb4
commit c4fec2bf97
3 changed files with 61 additions and 8 deletions

View file

@ -82,7 +82,14 @@
{/if} {/if}
<div class="toTop"> <div class="toTop">
⬆ {_to_top} <div id='to_up'>
<svg id="to_up_icon" viewBox="0 0 10 6"><polygon points="0 6 5 0 10 6 0 6"/></svg>
<span>{_to_top}</span>
</div>
<div id='to_back'>
<svg id="to_back_icon" viewBox="0 0 10 6"><polygon points="0 0 5 6 10 0 0 0"/></svg>
</div>
</div> </div>
<div class="layout"> <div class="layout">

View file

@ -1381,7 +1381,7 @@ textarea {
.toTop { .toTop {
position: fixed; position: fixed;
padding: 20px; padding: 12px;
width: 100px; width: 100px;
height: 100%; height: 100%;
background-color: #f3f3f3; background-color: #f3f3f3;
@ -1391,9 +1391,34 @@ textarea {
opacity: 0; opacity: 0;
transition: .1s all; transition: .1s all;
z-index: 129; z-index: 129;
user-select: none;
} }
body.scrolled .toTop:hover { .toTop > div svg {
display: inline-block;
margin-right: 2px;
width: 8px;
height: 7px;
fill: #3f3f3f;
}
.toTop > div span {
font-weight: bold;
}
.toTop.has_down #to_up, .toTop #to_back {
display: none;
}
.toTop.has_down #to_back {
display: block;
}
.toTop.has_down {
opacity: .3;
}
body.scrolled .toTop:hover, .toTop.has_down:hover {
opacity: .5; opacity: .5;
cursor: pointer; cursor: pointer;
} }

View file

@ -1,14 +1,35 @@
window.addEventListener("scroll", function(e) { window.addEventListener("scroll", function(e) {
if(window.scrollY < 100) { if(window.scrollY < 100) {
if(window.temp_y_scroll) {
u('.toTop').addClass('has_down')
}
document.body.classList.toggle("scrolled", false); document.body.classList.toggle("scrolled", false);
} else { } else {
document.body.classList.toggle("scrolled", true); document.body.classList.toggle("scrolled", true);
u('.toTop').removeClass('has_down')
} }
}); });
u(".toTop").on("click", function(e) { u(".toTop").on("click", function(e) {
window.scrollTo({ const y_scroll = window.scrollY
top: 0, const scroll_margin = 20
behavior: "smooth"
}); if(y_scroll > 100) {
}); window.temp_y_scroll = y_scroll
window.scrollTo(0, scroll_margin)
window.scrollTo({
top: 0,
behavior: "smooth"
})
} else {
if(window.temp_y_scroll) {
window.scrollTo(0, window.temp_y_scroll - scroll_margin)
window.scrollTo({
top: window.temp_y_scroll,
behavior: "smooth"
})
}
}
u(document).trigger('scroll')
})