Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slideToggle() on <tr> causes "jump"

Tags:

html

jquery

When using jQuery slideToggle() function to show/hide data on a new row in a table it causes it to stutter. Yet, when using slideToggle() to show/hide a <div> it works very smoothly.

Can anyone tell me why this happens?

Fiddle example: http://jsfiddle.net/gLGUG/

jQuery code:

$("tr").click(function () {
    $(".slideMe").slideToggle();
});

$(".slideMeDiv, button").click(function () {
    $(".slideMeDiv").slideToggle();
});

HTML Markup:

<table>
    <tr>
        <td>One Row</td>
    </tr>
    <tr>
        <td>Click me</td>
    </tr>
    <tr class="slideMe">
        <td>SlideDOWN</td>
    </tr>
</table>
<br />
<button>Slide Div</button>

<div class="slideMeDiv">
    Slide me as well
</div>
like image 303
97ldave Avatar asked Jun 14 '13 09:06

97ldave


2 Answers

Mention the border="0" cellspacing="0" cellpadding="0" in the table

<table width="100%" border="0" cellspacing="0" cellpadding="0">

this will solve the jumping issue

Here is the jsFiddle File


Also for sliding effect you need to wrap your text with a div and place the div in-side the td

here is the updated jsFiddle File

like image 155
Roy Sonasish Avatar answered Nov 15 '22 23:11

Roy Sonasish


I just do this in my js

$(document).ready(function(){
    $('tr').click(function(){
        $('.slideMe').slideToggle();
        $('.slideMe').css("display", "block")
    });
});

This stops the tr tag displaying as table-row which doesn't work with a slide toggle

like image 27
BritishSam Avatar answered Nov 16 '22 00:11

BritishSam