I created a script to fade in a scroll to top button when $(document).scrollTop() > 100
, and fade it out when this is not true. This is done by:
$.fn.scrollToTop = function() {
$(window).scroll(function() {
if( $(this).scrollTop() > 100) {
$('.scroll-back').fadeIn();
} else {
$('.scroll-back').fadeOut();
}
});
}
and to use it I do:
$(document).ready(function() {
$(document).scrollToTop();
}
The button works fine when just scrolling, but if I resize my window / open inspect element when scrolled to the top of the page, the button fades out then fades back in rapidly, any ideas how can I fix this?