$(function(){ $(window).scroll(function() { var scroll = getCurrentScroll(); if ( scroll >= 300 ) { $('.scroll-top').css('opacity','1'); } else { $('.scroll-top').css('opacity','0'); } }); function getCurrentScroll() { return window.pageYOffset; } $('a.page-scroll').bind('click', function(event) { var $anchor = $(this); $('html, body').stop().animate({ scrollTop: $($anchor.attr('href')).offset().top }, 2000, 'easeInOutExpo'); event.preventDefault(); }); });