I have this code. I want the toggle to have an easeOut animation every time it opens and closes, but it only works when opening it the first time.
$('.toggle-content:not(.opened), .content-tab:not(.opened)').hide();
$('.tab-index a').click(function () {
$(this).parent().next().slideToggle(300, 'easeOutExpo', function () {
if ($(this).is(':visible'))
$(this).css('display', 'table-row');
else
$(this).css('display', 'hidden')
});
$(this).parent().toggleClass('tab-opened tab-closed');
$(this).children('i').toggleClass('icon-plus-sign icon-minus-sign');
$(this).attr('text', ($(this).attr('text') == 'Close') ? 'Open' : 'Close');
return false;
});
Here is an example of where I want to use it:
<div class="toggle">
<p class="tab-index tab-closed">
<a href="#" title="Close"><i class="icon-plus-sign"></i> text</a></p>
<div class="content-tab closed">
<p>text</p>
</div>
</div>
I expected it to have the animation every time I opened or closed the toggle, but I am new to CSS and I don’t know what exactly isn’t working. Thank you in advance for helping me out!
3
Answers
If I change the code to negate the visible property, the animation works, but the text in the content-tab overflows.
Image example here
Here's the new code:
and the .content-tab class
The HTML code remains like my original question
LE: Working code here Enjoy
You added multiple parameters in your
slideToggle
function, Remove theduration
(300) or theeasing
, And it will work, Here is an exampleSimple way:
Maybe you are using the other checks and instructions by purpose, but if not, here is an easy way, just use the
slideToggle
function, it will handle displaying the items for you without the other checks: