Reputation: 113
I have a table in the head i have a button when the button is clicked i wnt the table rows to slide down for that i have used slideToggle(); but that is not working instead of the smooth slide effect it just shows & hide i tried slideToggle('slow') & slideToggle(500) but it did not work
$(document).ready(function()
{
$("#submenu").hide();
$("#mbtn").click(function(){
$("#submenu").slideToggle(500);
});
});
Upvotes: 0
Views: 1381
Reputation: 1072
The ready-made animation methods are for block-level elements only. To wok with you can set tbody element as block level element.
<script type="text/javascript" src="https://code.jquery.com/jquery- 1.10.2.js"></script>
<table class="table table-hover">
<thead>
<tr>
<th id="mbtn" class="btn" style="text-align:center;"><h1>Menu</h1> </th>
</tr>
</thead>
<tbody id="submenu" style="display:block">
<tr><td>Projects</td></tr>
<tr><td>Contributers</td></tr>
<tr><td>Submit project</td></tr>
<tr><td>Contact us</td></tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function()
{
$("#submenu").hide();
$("#mbtn").click(function(){
$("#submenu").slideToggle("slow");
});
});
</script>
Upvotes: 0
Reputation: 109
Your jQuery looks correct. I believe the issue is with using slideToggle on #submenu which is a tbody element. The slideToggle function works by reducing the elements height, over the specified time to 0, then display:none. To fix this simply apply display: block to #submenu.
#submenu {
display: block;
}
Upvotes: 1
Reputation: 1010
slideToggle does not work with table elements. Good news is, you don't need a table to build a menu, in fact this is how we do it in a more semantic way :
<nav class="menu">
<span class="btn">Menu</span>
<ul>
<li><a href="">Projects</a></li>
<li><a href="">Contributors</a></li>
<li><a href="">Contact us</a></li>
</ul>
</nav>
You can also pass on the javascript for the animation, and use CSS animations. Check out this example.
Upvotes: 1