Witam, próbowałem zrobić script, który będzie zmieniał klasę divowi po przeskrollowaniu danej wysokości, znalazłem parę skryptów ale w JQuery, a chcę pisać w JS.
Wklejam kod i scrypt który wyskrobałem :P
<div class="toTopButton">Do góry</div>
.toTopButton {
display: none;
}
@media (min-width: 1024px) {
.toTopButton {
display: block;
border-radius: 99px 99px;
text-align: center;
background-color: #1c74b2;
font-size: 20px;
line-height: 20px;
width: 8vw;
height: 4vh;
padding: 10px;
position: fixed;
bottom: 15px;
right: 15px;
cursor: pointer;
}
}
@media (min-width: 1400px) {
.toTopButton {
width: 7vw;
}
}
if (toTopButton) {
toTopButton.addEventListener("click", function () {
window.scrollBy(0, -1 * window.pageYOffset);
})
}
if ( pageYOffset > "40") {
toTopButton.classList.toggle('active');
}
coś zrobiłem źle ? Proszę o pomoc :)