I donβt know how to solve your current problem with a proper callback based solution (there is not enough information about the Ticker plugin that you use), but I can explain what is wrong with your current code:
var ticker = setTimeout(runTicker(), 8000);
Do not call runTicker immediately. You want to pass this function, not the result of its call, to setTimeout . The number [plain integer] will be returned and assigned by ticker . It can be used to identify a timeout when it is interrupted with clearTimeout - and nowhere else.
$.when(ticker)...
creates a new Deferred Now. Look at his documentation : it will combine objects with deferred with each other and create immediately resolved Promises for any other values ββ- for example, numbers. Therefore, your done callback is also called with an error, and again you make an error with Other instead of passing it to setTimeout .
Since the plugin you use seems very limited regarding callbacks, I wrote my own now (just for fun :-). It adapts my solution from this former answer , which uses elegant DOM methods. It is written as a standard jQuery plugin, it even supports the stop and go methods and, most importantly, integrates well into the jQuery fx queue. This means that you can use it just like animate() with respect to callbacks and chains, and if you want to work with Deferreds, you can call the promise() method to get a promise for the end of the queue. Call example:
$('#ticker').fadeOut().delay(2000).typewriter({framerate:1000/30}, function() { // the typewriter effect has just ended }). ... .promise().done(function() { // effect queue has ended - start Other() }); jQuery(".stop").click($.fn.typewriter.bind($("#ticker"), "stop"));
Bergi Nov 14 '12 at 18:56 2012-11-14 18:56
source share