Jump to content

jquery: Sliding a table row up


hawkagent

Recommended Posts

Hello,

 

I'm trying to use .slideUp() to smoothly slide up a table row with text and image, however when I do this, the animation looks very sloppy, here you can see what I'm talking about:

 

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js"></script>
   <script type="text/javascript" language="javascript">
   
    $(document).ready(function() {

      $("#hide").click(function(){
         $(".target").slideUp( "slow");
      });

      $("#show").click(function(){
         $(".target").show( "slow");
      });

   });
   </script>
   <style>
      p {
           background-color:#bca;
           width:200px; 
           border:1px solid green; 
        }
     div{ width:100px; 
            height:100px; 
            background:red;  
        }
  </style>
</head>
<body>

   <button id="hide"> Hide </button>
   <button id="show"> Show</button> 
  <table>
<tr><td>1</td><td>1</td><td>1</td></tr>
<tr ><td>1</td><td>1</td><td>1</td></tr>
<tr class="target"><td >1</td><td>1</td><td>1</td></tr>
<tr><td>1</td><td>1</td><td>1</td></tr>
</table>
   <div class="target">
   </div>
  
</body>
</html>

 

If you run this script and press hide, that table columns get out of place before sliding up. Is there any way to fix this?

 

Thanks in advance

Link to comment
Share on other sites

-tr's cannot have widths and heights set.

-td's cannot have a height of 0, otherwise they'll collapse into one column.

-Best way to do it is to include divs inside each cell...

 

Try this:

 


<html>
    <head>
        <title>the title</title>
        <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.pack.js"></script>
        <script type="text/javascript" language="javascript">           
            $(document).ready(
                function(){
                    $("#hide").click(
                        function(){
                            $("tr.target td div").slideUp("slow", function(){
                                //$(this).parent().parent().fadeOut();
                            });
                        }
                    );
                    
                    $("#show").click(
                        function(){
                            $(".target").show("slow");
                        }
                    );
               }
            );
        </script>
        <style>
            p{
                background-color:#bca;
                width:200px;
                border:1px solid green;
            }
            div{ 
                width:auto;
                height:auto;
                background:red; 
            }
            table, td, tr{
            }
        </style>
    </head>
<body>

<button id="hide"> Hide </button>
<button id="show"> Show</button>
<table>
    <tr><td>1</td><td>1</td><td>1</td></tr>
    <tr><td>1</td><td>1</td><td>1</td></tr>
    <tr class="target"><td><div>1</div></td><td><div>1</div></td><td><div>1</div></td></tr>
    <tr><td>1</td><td>1</td><td>1</td></tr>
</table>
<div class="target">
</div>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.