Blink and marquee!

9 February 2011 · 1 minute read · jquery · doing-it-wrong · web

Recently I’ve blogged about creating the a blink tag with jQuery, I’ve also blogged about making a marquee tag.

Well can we combine them? Sure we can! But with $.Deferred() there’s some more cool things we can do, like this:

$.when($('h1').blink({ count: 5 }), $('h1').marquee({ count: 1 }))
    .done(function() {
        $('h1').css('color', '#f00');
    });

Once both the plugins have completed the text will turn red.

Without wanting to get too deep into how Deferred works (read the doco for that) the high-level view is that when all the methods that are passed into $.when raise deferred.resolve (it only works if they use promise and such properly), but yeah, that’s how you can have a function invoked when all the deferred method complete!

Hey, you could even do this:

$.when($(.get('/foo'), $('h1').blink({ count: 5 }))
    .done(function() {
        $('h1').css('color', '#f00');
    });

Blink & AJAX, how awesome!

Here’s a jsfiddle if you want to play too.


Published: 2018-05-29 16:49:01 +1000 +1000, Version: aaf7f73