jQuery - Back to top

0 votes
154 views
added Jun 26, 2019 in jQuery by LC Marshal Captain (25,790 points)
$('#back_top').click(function(){
  $('html, body').animate({scrollTop:0}, 'normal');
  return false;
});

$(window).scroll(function() {
  if($(this).scrollTop() !== 0) {
    $('#back_top').fadeIn();	
  } else {
    $('#back_top').fadeOut();
  }
});

if($(window).scrollTop() !== 0) {
  $('#back_top').show();	
} else {
  $('#back_top').hide();
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...