$(function(){ $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']'); if ($target.length) { if($(window).width() > 1200){ var targetoffset = $target.offset().top-62; }else{ var targetoffset = $target.offset().top-$('#header').outerheight(); } $('html,body').animate({scrolltop: targetoffset}, 10); return false; } } }); $('#side .pagetop a').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']'); if ($target.length) { if($(window).width() > 1200){ var targetoffset = $target.offset().top-62; }else{ var targetoffset = $target.offset().top-$('#header').outerheight(); } $('html,body').animate({scrolltop: targetoffset}, 1000); return false; } } }); });