jQuery: the explode() plugin

This plugin works in a destructive way, in the sense that its primary use is related to the removal of certain page elements where they're no longer needed. In its essence, it is as follows:

/** jQuery explode() plugin

   
   Adds a simple exploding effect to a jQuery's element
   and then removes the element from the DOM
   
   Usage: $(element).explode(speed);
   speed: any value accepted by the animate() method
   
   @author Gabriele Romanato <http://onwebdev.blogspot.com>
   @version 1.0  */
   
   
   


(function($) {
 
 $.fn.explode = function(speed) {
  
  var self = this;
  
     return this.each(function() {
     
         speed = speed || 'fast';
  
      var winWidth = $(window).width();
      var winHeight = $(window).height();
  
      self.animate({
       
       display: 'block',
       width: winWidth,
       height: winHeight,
       opacity: '0'
   
   
      }, speed, function() {self.remove();});
  
     }); 
  
 };
 
})(jQuery);

It accepts as its sole parameter a speed value which corresponds to the values accepted by the animate() method. When the animation is complete, the element is removed from the DOM. Note also that it turns an element into a block-level one by operating on its CSS display property (remember that setting width and height on an inline element doesn't work).

Live example

Live example

Download

jquery.explode.js

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.