Line 994: | Line 994: | ||
// Add smooth scrolling on all links inside the navbar | // Add smooth scrolling on all links inside the navbar | ||
− | var animateScroll = function(target, offset) { | + | var animateScroll = function(target, offset, speed) { |
var is = $(document).scrollTop(); | var is = $(document).scrollTop(); | ||
var must = parseInt($(target).offset().top) + offset; | var must = parseInt($(target).offset().top) + offset; | ||
+ | if (typeof speed == 'undefined') { | ||
+ | speed = Math.sqrt(Math.pow(is - must, 2)) / 200 | ||
+ | } | ||
var setTo; | var setTo; | ||
if (is < must) { | if (is < must) { | ||
− | setTo = is + | + | setTo = is + speed; |
if (setTo > must) { | if (setTo > must) { | ||
setTo = must; | setTo = must; | ||
} | } | ||
} else if (is > must) { | } else if (is > must) { | ||
− | setTo = is - | + | setTo = is - speed; |
if (setTo < must) { | if (setTo < must) { | ||
setTo = must; | setTo = must; | ||
Line 1,012: | Line 1,015: | ||
$(document).scrollTop(setTo); | $(document).scrollTop(setTo); | ||
if (setTo != must) { | if (setTo != must) { | ||
− | setTimeout(function() {animateScroll(target, offset);}, 10); | + | setTimeout(function() {animateScroll(target, offset, speed);}, 10); |
} | } | ||
} | } |
Revision as of 21:43, 31 October 2017