javascript - .done() callback when using custom jQuery Animations -
i'm using following functions in order animate slides slideup()
or slidedown()
:
(function($) { jquery.fn.slidelefthide = function(speed, callback) { this.animate({ width: "hide", paddingleft: "hide", paddingright: "hide", marginleft: "hide", marginright: "hide" }, speed, callback); } jquery.fn.slideleftshow = function(speed, callback) { this.animate({ width: "show", paddingleft: "show", paddingright: "show", marginleft: "show", marginright: "show" }, speed, callback); } })(jquery);
the thing is, want call function only once after animation ends. tried doing by:
$(".item").slidelefthide(function() { $(this).remove(); }).done(function() { $(".tab").each(function() { $(this).attr('data-status', 'success'); }); });
when execute code, error message saying cannot read property 'done' of undefined
. same happens .then()
instead of .done()
.
how can solve this?
thanks!
(function ($) { function slideleftbinder(action) { return function () { var = 0, speed = ((number(arguments[i]) === parsefloat(arguments[i]) && !isnan(arguments[i])) || undefined) && arguments[i++], callback = (typeof arguments[i] === 'function' || undefined) && arguments[i++], self = this; return new promise(function (resolve) { var completed = 0; self.animate({ width: action, paddingleft: action, paddingright: action, marginleft: action, marginright: action }, { duration: speed, complete: callback, always: function() { if (self.length === ++completed) { resolve(self); } } }); }); }; } jquery.fn.slidelefthide = slideleftbinder('hide'); jquery.fn.slideleftshow = slideleftbinder('show'); })(jquery);
use this:
$(".item") .slidelefthide(function() { $(this).remove(); }) .then(function(selector) { console.log('selector: ', selector); $(".tab").attr('data-status', 'success'); });
Comments
Post a Comment