J'ai un problème lors de la création d'une fonction de rappel. Tout d'abord, pour autant que je puisse comprendre, un rappel agit comme un paramètre qui se déclenche quand toute l'action de sa fonction "parent" est terminée. Par exemple:Fonction de rappel Jquery
$('p').hide('slow', function() {
$(this).show('slow');
});
Dans un premier temps <p>
est caché, et seulement après, il montre à nouveau. Comment puis-je appliquer un tel rappel dans un plugin aléatoire?
Comment puis-je appliquer un tel rappel dans un plugin aléatoire?
Par exemple, un plug-in ressemble à ceci:
$.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*/
}
});
});
Qu'essayez-vous exactement d'accomplir? – quantumSoup
J'essaye un callback pour fonctionner correctement, comme dans la plupart des méthodes jquery. $ (document) .ready (function() {* Tout se passe ici quand Dom est chargé mais pas avant, donc c'est un callback * /}); Et je voudrais savoir comment écrire un rappel dans mon plugin – tylik