openvk/Web/static/js/scroll.js

36 lines
947 B
JavaScript
Raw Normal View History

2020-06-07 19:04:43 +03:00
window.addEventListener("scroll", function(e) {
if(window.scrollY < 100) {
2024-11-02 13:02:34 +03:00
if(window.temp_y_scroll) {
u('.toTop').addClass('has_down')
}
2020-06-07 19:04:43 +03:00
document.body.classList.toggle("scrolled", false);
} else {
document.body.classList.toggle("scrolled", true);
2024-11-02 13:02:34 +03:00
u('.toTop').removeClass('has_down')
2020-06-07 19:04:43 +03:00
}
});
u(".toTop").on("click", function(e) {
2024-11-02 13:02:34 +03:00
const y_scroll = window.scrollY
const scroll_margin = 20
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')
})