Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.78 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Need help reversing a function; reverting an animated expansion of a div
  2. jQuery().ready(function() {
  3.  
  4.     // Variables - Project Tiles
  5.     var $tile = jQuery(".tile");
  6.  
  7.     //Expands tile on click
  8.     jQuery($tile).click(function(){
  9.         $tile
  10.             .stop()
  11.             jQuery(this).addClass('expanded'); //change cell's class
  12.             jQuery(".tile-content", this).hide(); //hide starting content
  13.             jQuery(this).animate({ //animate the expansion of the cell
  14.                 width: '933px',
  15.                 height: 'auto',
  16.             }, "slow", function() { //things to do after animation
  17.                 jQuery(".expanded-content", this).fadeIn('slow'); //show post content
  18.                 jQuery("#content").isotope({  //re-arrange tiles
  19.                     sortBy : 'width',
  20.             });
  21.         });
  22.     });
  23.     //  close tile
  24. });
  25.        
  26. <div id="container">
  27.   <div class="tile-holder">
  28.     <div class="tile"></div>
  29.   </div>
  30.   <div class="tile-holder">
  31.     <div class="tile"></div>
  32.   </div>
  33.   ...
  34. </div>
  35.        
  36. jQuery(function(){
  37.  
  38.   var $container = jQuery('#container'),
  39.       $tileHolders = jQuery('.tile-holder');
  40.  
  41.   $container.isotope({
  42.     itemSelector: '.tile-holder',
  43.     masonry: {
  44.       columnWidth: 60
  45.     },
  46.     getSortData : {
  47.       width : function( $item ){
  48.         // sort by biggest width first, then by original order
  49.         return -$item.width() + $item.index();
  50.       }
  51.     },
  52.     sortBy : 'width'
  53.   })
  54.  
  55.   $tileHolders.click(function(){
  56.     var $this = jQuery(this),
  57.         tileStyle = $this.hasClass('big') ? { width: 50, height: 50} :
  58.           { width: 170, height: 110};
  59.     $this.toggleClass('big');
  60.  
  61.     $this.find('.tile').stop().animate( tileStyle );
  62.     // update sortData for new tile's width
  63.     $container.isotope( 'updateSortData', $this ).isotope();
  64.  
  65.   });
  66.  
  67. });