jQuery callback syntax layout?
When i use a jqu开发者_如何学Goery function like so,
jQuery('.mediaContainer').dialog({ width: 500, height:500});
how do i set a callback? where would i place it?
thanks
dialog has several events you can set. You can see them here:
http://jqueryui.com/demos/dialog/#event-close
For instance to set an function to run on close:
$( ".mediaContainer" ).dialog({
close: function(event, ui) { //do stuff }
});
There are a number of events you can use: beforeClose, open, focus, dragStart, resizeStart, resize, resizeStop, and close. Each of these events can trigger a callback function, so you actually have a lot of control.
Typically it would appear after the last of the arguments in whichever method you wanted to insert the call-back into, for example:
jQuery('.mediaContainer').dialog({ width: 500, height:500},
function(){
// callback stuff here.
});
This assumes that .dialog()
is some form of plug-in, or function that will, or can, accept a call-back. To use a standard jQuery function (animate()
):
$(this).animate({'opacity': 1, 'height': '200px'}, 500, function(){
// callback stuff.
});
精彩评论