jQuery: puff effect

Scriptaculous provides a nice Puff() effect which consists of a simple increase in the element's dimension and an adjustment of their opacity to zero. We can actually mimic this effect with jQuery by creating a puff() plugin which accepts two options, factor and speed. The former is the value by which the dimensions of the element will be incremented, while the latter is the speed of the overall animation. Here's the jQuery code:

(function($) {

  $.fn.puff = function(options) {
    options = $.extend({
      factor: 3,
      speed: 100
    }, options);
    return this.each(function() {
        width: $(this).width() * options.factor,
        height: $(this).height() * options.factor,
        opacity: 0
      }, options.speed);


An example:

$('#run').click(function(e) {
  $('#test').puff({factor: 4, speed: 200});

You can see a demo below.


Live demo

This entry was posted in by Gabriele Romanato. Bookmark the permalink.

Leave a Reply

Note: Only a member of this blog may post a comment.