Currently, I am troubleshooting an issue with the transition effect between adding and removing two classes fixed-top
and fixed-bottom
. Even though I have included CSS properties for smooth transitions, such as:
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
I have also implemented JavaScript code for the scroll behavior:
var lastScrollTop = 0;
$(window).scroll(function(event) {
var st = $(this).scrollTop();
if (st > lastScrollTop) {
if (st > 500) {
$('.box').removeClass("fixed-bottom").addClass("fixed-top");
}
} else {
if (st < 500) {
$('.box').removeClass("fixed-top").addClass("fixed-bottom");
}
}
lastScrollTop = st;
});
html,
body {
height: 100%;
}
.container {
height: 2000px;
}
.box {
width: 100%;
height: 50px;
background: #777;
}
.fixed-top {
position: fixed;
top: 0;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
.fixed-bottom {
position: fixed;
bottom: 0;
-webkit-transition: all 3s ease;
-moz-transition: all 3s ease;
-o-transition: all 3s ease;
transition: all 3s ease;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="box fixed-bottom"></div>
</div>