The animation function is implemented on setTimeout () through recursion. How can I stop its execution from another function?
animate: function(itm, prop, unit, fromVal, toVal, time, callback){ slider.sett.progress = true; var fps = .06; var frame = 0; var direction = fromVal < toVal ? true : false; var distance = direction ? (toVal - fromVal) : (fromVal - toVal); var delta = distance / time / fps; var handle = setTimeout(function run() { frame++; var step = delta * frame; var value = direction ? (fromVal + step) : (fromVal - step) ; itm.style[prop] = value + unit; if (direction && value < toVal || !direction && value > toVal) { setTimeout(run, 1 / fps); } else { itm.style[prop] = value + unit; slider.sett.progress = false; callback ? callback() : false; } }); },