2

My code doing slow to fast movements when i call scroll to top action any better solution to fix the smoothness?

my code:

(function () {
    var top_link = '';
    top_link = $(".top");
    var pos = top_link.offset();

    $(window).scroll(function () {

        if ($(this).scrollTop() > 150) {
            top_link.fadeIn();
        } else if ($(this).scrollTop() <= 150) {
            top_link.fadeOut();
        }
    });
})();

$(".top").click(function () {
    $("html, body").animate({
        scrollTop: 0
    }, 600);
    return false;
});
Marcin
  • 184
  • 1
  • 2
  • 12
Neo
  • 49
  • 8

1 Answers1

1

Please Update your Code :

(function () {
    var top_link = '';
    top_link = $(".top");
    var pos = top_link.offset();

    $(window).scroll(function () {

        if ($(this).scrollTop() > 50) {
            top_link.fadeIn('slow');
        } else if ($(this).scrollTop() <= 50) {
            top_link.fadeOut('slow');
        }
    });
})();

$(".top").click(function () {
    $("html, body").animate({
        scrollTop: 0
    }, 500);
    return false;
});

Thanks