So I need to call a function and interrupt another, anyone know how to do?
You can't literally do that, because JavaScript on browsers is single-threaded (barring the use of Web Workers, but you only have on UI thread even then). So you can't interrupt the execution of a function call.
But if you're using jQuery's animation/effects functions, the calls you make just put actions in a queue that jQuery then runs asynchronously, and you can interrupt that, by calling stop
on the element.
So by way of example:
function kickThingsOff() {
// These could all be written in one line as a chain, but I'm doing them
// separately for emphasis
var elm = $("#myElement");
elm.fadeOut("slow");
elm.fadeIn("slow");
elm.slideUp("slow");
}
function interruptIt() {
$("#myElement").stop(true, true);
}
You can't actually interrupt kickThingsOff
in the middle (between, say, the fadeIn
line and the slideUp
line), but you can interrupt the animation it queues up via stop
.