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

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 1.23 KB  |  hits: 4  |  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. How do I use the properties created by an animate function in that animate function's callback?
  2. <script type="text/javascript">
  3. $(document).ready(function(){
  4.     $(".ExampleImage").toggle(
  5.         function(){
  6.             var Image = $(this);
  7.             var Container = $(this).closest(".ImageContainer");
  8.             Image.switchClass("ExampleImageContracted","ExampleImageExpanded",500);
  9.             Container.css('height','auto');
  10.             Image.queue(scrollToExample(Image));
  11.         },
  12.         function(){
  13.             var Image = $(this);
  14.             var Container = $(this).closest(".ImageContainer");
  15.             Image.switchClass("ExampleImageExpanded","ExampleImageContracted",500);
  16.             Container.animate({'height':'250'},500,scrollToExample(Image));
  17.         }
  18.     );
  19.  
  20.     function scrollToExample(Image) {
  21.         var NewTop = $(Image).closest(".Example").offset();        
  22.         $('html, body').animate( {
  23.             scrollTop:NewTop.top
  24.         }, 1000);  
  25.     }
  26. });
  27. </script>
  28.        
  29. Image.queue(scrollToExample(Image));
  30. ...
  31. Container.animate({'height':'250'},500,scrollToExample(Image));
  32.        
  33. Image.queue(function() { scrollToExample(Image); });
  34. ...
  35. Container.animate({'height':'250'},500,function(){scrollToExample(Image);});