A helpful SO answer taught me how to toggle an element by sliding it horizontally instead of vertically.
$('div').animate({ width: 'toggle' });
However, a new problem arises when text is in the element - the animated width introduces word wrap and other sensitive elements react poorly.
When animating, the height of it jumps all over the place and the effect is quite unpleasant. This snippet fully demonstrates the problem:
$('a').click(function() {
$('div').animate({
width: 'toggle'
});
});
div {
background-color: red;
width: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div>a b c d e f g h</div>
<a href="#">test</a>
I would like to see it like a static image - if the word wrap makes two lines, it should stay as two lines as it animates. Everything else is already cool and dandy.