UNPKG

vanilla-js

Version:

jQuery-like Aliases (NOT Wrappers) to HTML5 Selector API / Raw Document

65 lines (62 loc) 1.73 kB
// Generated by CoffeeScript 1.4.0 $.ui.animation = function(e, params) { var step, _this = this; e.data('step', step = function(index) { e.data('animation_index', index); return params.step(e, index); }); e.data('stop', function() { return e; }); return e.data('animate', function(to, duration, from) { var fps, frame, frames, index, is_numeric, mspf, stop; if (duration == null) { duration = 'slow'; } if (from == null) { from = null; } is_numeric = function(v) { return (!isNaN(v)) && v !== null && v; }; from = index = is_numeric(from) || is_numeric(from = typeof params.from === 'function' ? params.from() : params.from) || is_numeric(from = e.data('animation_index')) || 0; if (to === from) { return; } fps = params.fps || 8; frame = 0; frames = (duration / 1000) * fps; mspf = duration / frames; e.data('stop', stop = function(jumpToEnd) { var timer; if (timer = e.data('animating')) { clearTimeout(timer); if (jumpToEnd) { params.step(e, to); } } return e; }); stop(); return (function() { if (frame < frames) { index = $.ui.easing.easeOutSine(frame, from, to, frames); frame += 1; step(index); return e.data('animating', setTimeout(arguments.callee, mspf)); } else { params.step(e, to); e.data('animation_index', to); if (params.complete) { return params.complete.call(e, to); } } })(); }); }; $.ui.easing = { easeOutSine: function(frame, from, to, frames) { return (to - from) * Math.sin(frame / frames * (Math.PI / 2)) + from; } };