jQuery addClass example
Change class name on click in jQuery
HTML
<div class="top"43423234></div>
<div class="to">fds</div>
CSS
body {
margin: 0;
height: 10000px;
}
.top {
background-image: linear-gradient(to top, #8993be, #242993);
height: 100vh;
}
JavaScript
var position = $(window).scrollTop();
function tt(){
$('html,body').animate({
scrollTop: $('.to').offset().top
}, 750);
}
function tt(){
$('html,body').animate({
scrollTop: $('.to').offset().top
}, 750);
}
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if(scroll > position) {
tt();
console.log('scrollDown');
} else {
console.log('scrollUp');
}
position = scroll;
});
$('.top').click(function() {
tt();
});