I have a scrolltotop icon that appears when the window is scrolled down a bit. The thing is when the window is scrolled to the bottom of the page it overlaps a div which I do not want.
I would like to make it so the top position of scrolltotop gets animated upwards just a bit to avoid colliding with the div when the window is scrolled all the way to the bottom
Here's what I have so far: https://jsfiddle.net/qn6h9qad/
jQuery:
//Scroll to top animate in
$(window).scroll(function(){
if ($(this).scrollTop() < 300) {
$('.scrollToTop').fadeOut(1000).css({right:-70});
} else {
$('.scrollToTop').fadeIn(1000).css({right:20});
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},1000);
return false;
});
You need to add an extra condition to the scroll event on the window:
if(($(this).scrollTop() + $(this).height()) > $('.projnav').position().top){
$('.scrollToTop').css(bottom, 40);
}
else{
$('.scrollToTop').css(bottom, 20);
}
To make the animation smooth just add:
.scrollToTop{
transition: all .5s;
}
Fiddle working: http://jsfiddle.net/qn6h9qad/5/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With