JavaScript easing Scroll to Element, ohne großes Framework.
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();
function animateScrollTo(id) {
var node = document.getElementById(id);
if (node) {
var to = 0;
var from = window.pageYOffset;
do {
to += node.offsetTop;
// from += node.offsetParent ? node.offsetParent.scrollTop : 0;
node = node.offsetParent;
} while (node)
if (from == to) return;
var start = Date.now();
var tick = function() {
var t = Math.min(1, ((Date.now() - start) / 1000));
var eased = t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1;
var val = (eased * (to - from)) + from;
window.scrollTo(0, val);
if (t<1) {
window.requestAnimFrame(tick);
}
};
tick();
}
}