Closures
Every time you call slimScroller.scroll()
you're recreating the following functions:
var easeInOutCubic = function (time) {
return (time < 0.5) ? 4 * time * time * time : (time - 1) * (2 * time - 2) * (2 * time - 2) + 1;
};
var position = function (start, end, elapsed, duration) {
return (elapsed > duration) ? end : start + (end - start) * easeInOutCubic(elapsed / duration);
};
Recreating requestAnimationFrame
variable:
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
Recreating this function as well:
var step = function () {
var elapsed = Date.now() - clock;
var finalPosition = position(start, targetPosition, elapsed, duration);
if(horizontal){window.scroll(finalPosition, 0);}else{window.scroll(0, finalPosition);}
if (elapsed > duration) {
if (callback) {
callback(window.scrollY);
}
} else {
requestAnimationFrame(step);
}
};
also why do you wrap this around try catch
:
try{
parseSelector = document.querySelector(target);
}catch(e){}
Last thing don't use console.error();
Line 35
Throw an Error
instead:
throw Error('Unknown type as target');
**It seems like you're just learning javascript so instead of doing a pull request I'll let you take care of these issues and I'll help you as you fix this