snovapavel,
ошибки не существенные, могли бы сами точки с запятыми добавить или можно не обращать внимания.
$(function() {
var duration = 2000,
play = false;
function swingFromTo(a) {
var b = 1.70158;
return (a /= 0.5) < 1 ? 0.5 * a * a * (((b *= 1.525) + 1) * a - b) : 0.5 * ((a -= 2) * a * (((b *= 1.525) + 1) * a + b) + 2);
}
$("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 (play) return;
play = true;
var d = performance.now();
var from = window.pageYOffset;
var to =
target.offset().top;
window.requestAnimationFrame(function foo(a) {
a = (a - d) / duration;
if(1 < a) a = 1;
var progress = swingFromTo(a);
window.scrollTo(0, from - (from - to) * progress);
if (a == 1) play = false;
else window.requestAnimationFrame(foo);
});
return false;
}
}
});
});