tags:

views:

34

answers:

3

I have a simple jquery function that resizes a table when it is clicked.

    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>

 <script type="text/javascript">
  $(document).ready(function()
  {
   $('.expand_table').live("click", function()
   {
       $('.expand_table').attr('width', 800);
   }); 
  });
 </script>

How would I build on this to make the table smoothly expand or grow to the new size?

A: 

Use the animate function with more options

animate

$(".expand_table").animate({ width: "800px" }, 1500 );
<script type="text/javascript">
 $(document).ready(function()
 {
  $('.expand_table').live("click", function()
  {
          //$('.expand_table').attr('width', 800);
                $(".expand_table").animate({ width: "800px" }, 1500 );
                // 1500 can be replaced with "slow", "normal", or "fast" or a 
                // number that specifies the speed of the animation
  }); 
 });
</script>
rahul
A: 

You can't animate an attribute, though. So you'd have to set the size in CSS.. Just switch

$('.expand_table').attr('width', 800);

for:

$('.expand_table').animate({ "width":"800px" }, 500); //uses 500ms to complete
peirix
Thanks. Is there a way I can stop the <tr>'s inside the table from shrinking during the resize? When the animation starts they get very small then when it animation finish pop to full size.
ian
I haven't looked into animating table sizes, but the `tr`'s shouldn't really pop in and out. Do you mean the `td`'s? You can set up separate animations for the table cells if you want...
peirix
yes it might be the tds. thanks.
ian
A: 

Refer to here:http://jqueryui.com/docs/Effects/Methods

Lots of example where you can apply on.

Best

samer