Show scroll to top if top != 0


/ Published in: jQuery
Save to your folder(s)

If scrollTop isnt equal to 0 then show #toTop


Copy this code and paste it in your HTML
  1. //Hide/Show #toTop
  2. jQuery(window).scroll(function () {
  3. if (jQuery(this).scrollTop() != 0) {
  4. jQuery('#toTop').fadeIn();
  5. } else {
  6. jQuery('#toTop').fadeOut();
  7. }
  8. });
  9. //Scroll to top
  10. jQuery('#toTop').click(function () {
  11. jQuery('body,html').animate({
  12. scrollTop: 0
  13. }, 300);
  14. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.