Image stabilization function
function debounce (fn, wait) {
var timeout = null;
return function() {
if(timeout !== null) clearTimeout(timeout);
timeout = setTimeout(fn, wait);
} }
Throttling function
function throttle(fn, wait) { var valid = true; return function () { if(! valid){ return false; } valid = false; setTimeout(()=>{fn(); valid=true}, wait); }}