I have a div of which collapse and expands using slideToggle and easing.
$('button').click(function () {
$('div').slideToggle('2000', "easeOutBounce");
});
I want it when it slide’s Up to have a minimum height so that there always a small visible content of it.
So when it’s slide down has height:(div height) and on slideUp, height:10px;
Note that the div could have any amount of height so that’s why I am not using animation.
The best I could come up with is the following:
JS Fiddle demo.
This demo has some issues, however:
if/else ifstatement.each()to assign the ‘default’/’natural’ height of the div elements.divs aren’tposition: absolutethey shrink down to the baseline of the in-line elements (as they’redisplay: inline-block), this may not be a problem if they’refloat: left(orfloat: right, obviously).Hopefully it’s of use, but it’s certainly not ideal in its current state.
Edited to post the plugin-ised version of the above (it retains all the same issues as before):
JS Fiddle demo.
30, and represents the height to which you want the element to slide to. If there are no units supplied then the height is, by default, considered to be in pixels.a quoted string defining the type of easing to be used in the animation; without jQuery UI this is either ‘linear’ or ‘swing’. With jQuery UI other options may be possible, but this is untested. If unspecified the animation defaults to ‘linear.’Because using units in a quoted string causes the finalelse ifto return false (obviously, I suppose…sigh), please use only an unquoted numerical argument for this variable (or edit the plug in to properly deal with quoted strings with units…).A larger issue that I hadn’t realised until I posted this, is that the plugin version only allows one iteration of the animation. Which I’m confused about, though perhaps it’s obvious to someone else?
Okay, it appears to be the evaluation of the height in the
ifstatement. Using3emcaused the finalelse if:curH == toggleMinHeightto return false. Presumably due to the presence of the unit (em) in that variable. The above guidance has been edited to reflect that the units should not be used.References:
animate().:animatedselector.attr().click().each().height().is().