$(document).ready(function(){ $('.tabPILLS li a').on('click', function () { event.preventDefault(); var jumper = $(this).attr('href'); // $('.tabPILLS li a').removeClass('active'); // $(this).addClass('active'); if ($(window).width() > 767) { $("html, body").animate({ scrollTop: $(jumper).offset().top - 100}, 2000); }else{ $("html, body").animate({ scrollTop: $(jumper).offset().top - 20}, 2000); } }); }); window.onscroll = function() {scrollFunction()}; function scrollFunction() { if ($(window).width() > 767) { if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { //document.getElementById("backToTop").style.display = "block"; $("#backToTop").fadeIn(300); } else { //document.getElementById("backToTop").style.display = "none"; $("#backToTop").fadeOut(300); } } } // When the user clicks on the button, scroll to the top of the document function topFunction() { $('body,html').animate({scrollTop:0},500); }