I am building a custom jQuery plugin which allows the user to delete records within a table in real-time, among many other things. When the records are deleted, I would like the the background-color of the deleted table row to turn red, then slide up out of view.
Here is a snippet of my code below, which doesn't do any of the color changing animation, nor does it slide up the row. However, it does delete the row when what is supposed to be the slide up animation, finishes. Some things to know when reviewing the code below:
object.parent().parent().addClass('deleteHighlight', 1000, function() { //Fold the table row $(this).slideUp(1000, function() { //Delete the old row $(this).remove(); }); });
Here is the HTML on which this is being executed, nothing special:
<table class="dataTable"> <thead> <tr> <th> </th> <th>Title</th> <th>Content Snapshot</th> <th>Management</th> </tr> </thead> <tbody> <tr class="odd" id="11" name="1"> <td class="center width50"><a class="dragger"></a><a class="visibilityTrigger eyeShow"></a></td> <td class="center width150">Title</td> <td> <div class="clipContainer">Content</div> <div class="hide contentContainer">Content</div> <div class="hide URLContainer">my-url</div> </td> <td class="center width75"><a class="edit"></a><a class="delete"></a></td> </tr> </tbody> </table>
Could someone please provide an example of how I can fix this?
Thank you for your time.
I suspect this is partly a browser issue. You shouldn't really target <tr />
's since browsers interpret them differently. Additionally they behave differently than block elements.
In this example: http://jsfiddle.net/lnrb0b/3t3Na/1/ your code works partially in chrome. The <tr />
is allowed styling (unlike in some IE versions) but you can't animate it. If you make it display:block
no worries, but then it's a bit rubbish as a table :)
In this example: http://jsfiddle.net/lnrb0b/3t3Na/2/ you'll see I've animated the <td />
's but they barely work and painfully slowly at that.
Have a test of those and I'll try think of a solution in the meantime.
The most elegant way to handle the slide and removal is to wrap each td
's inner contents with a div
, and to simultaneously reduce the padding of the td
and the height of the div
s. Check out this simple demo: http://jsfiddle.net/stamminator/z2fwdLdu/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With