I have a problem in creating a callback function. First, as far as I can understand, a callback acts like a parametr which triggers when all the action in its "parent" function has finished. For example:
$('p').hide('slow', function() {
$(this).show('slow');
});
At first <p> is hidden, and only afterwards it shows again.
How can I apply such callback in a random plugin?
For example a plugin looks like this:
$.fn.myPlugin = function(settings) {
return this.each(function() {
settings = $.extend({ onShow: null }, settings);
$(this).hide('slow'); /*This action should happen first (First action)*/
if ( $.isFunction( settings.onShow ) )
settings.onShow.call(this);/*Callback should fire after First action has stopped*/
}
});
};
$(document).ready(function()
$('p').myPlugin({
onShow: function() {
alert('My callback!');/*Both actions(element hiding and alert )
fire simultaneously, but I need alert
to fire after element is hidden*/
}
});
});