I am trying to create a show / hide effect using toggle and animate.
I have created the following fiddle:
which uses this code:
<script>
$(document).ready(function(){
$('.moreinfo').hide();
$('.more').click(function (ev) {
var t = ev.target
$('#info' + $(this).attr('target')).slideToggle(500, function(){
console.log(ev.target)
$('#info2').animate({width: 570, height: 570, marginLeft: 0}, {duration: 2000},
"linear");
});
$(t).html($(this).is(':visible')? 'Hide Info (x)' : 'Show Info (+)')
});
return false;
});
</script>
Problems are as follows:
- I would like the text reveal and the animation to occur at the same time. Currently the text shows and then the animation begins.
- Once the animation has taken place, when I click on 'Hide Info (x)', I would expect the text to change back to 'Show Info (+)'. It does not do this. It continually shows 'Hide Info (x)'.
- How can the animation be reversed so that the blue box shrinks again?
Thanks for all your time and help on this in advance.