Page 1 of 1

Expanding box - auto height....??

Posted: Tue Jun 10, 2014 11:18 am
by simonmlewis
http://jsfiddle.net/theguywholikeslinux/87f4Y/
I want to create a DIV that can be expanded, but begins 'CLOSED' on load.
The purpose is for a mobile site's search results page. So the user can "expand menu" and the menu of <table> rows above, will magically appear so they can browse the categories should they wish to.

I've found a few of these expanding things, but they are all either set to a fixed height of pixels, or 100% which would fill the screen.
Is there a way to expand it "auto" so it just expands to the height of what is inside it...?

I've posted a link at the top. This is not for advertising, it is a method I have found that does part of what I want, but not the "auto" part.

Re: Expanding box - auto height....??

Posted: Tue Jun 10, 2014 11:21 am
by Celauran
Something like this? http://jqueryui.com/accordion/#collapsible

Note: I'm not necessarily suggesting adding a whole new library for just this one effect, I just want to make sure we're on the same page as to what you're looking for.

Re: Expanding box - auto height....??

Posted: Tue Jun 10, 2014 11:29 am
by simonmlewis
I'm gona sound dumb here - but I copied that code, and even copied their CSS from the style sheet mentioned, but it failed to work.

Code: Select all

 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="ttp://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<style>

 <script>
$(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
</script>

<div id="accordion">
<h3>Section 1</h3>
<div>
<p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
</div>
<h3>Section 2</h3>
<div>
<p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p>
</div>
<h3>Section 3</h3>
<div>
<p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>
</div>
<h3>Section 4</h3>
<div>
<p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est. </p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p>
</div>
</div>

Re: Expanding box - auto height....??

Posted: Tue Jun 10, 2014 11:33 am
by simonmlewis
Don't worry, I found one I recall doing once before - with 'bootstrap'. :)

Re: Expanding box - auto height....??

Posted: Tue Jun 10, 2014 11:36 am
by Celauran
You have an unmatched style tag and a src="ttp://etc..."

Re: Expanding box - auto height....??

Posted: Tue Jun 10, 2014 11:43 am
by simonmlewis
Yeah but the code only had // in the first place, and that didn't work either.
The Bootstrap version would brilliantly. It expands in an animated way, to the perfect height of what's inside it, and contracts. Really nice.
:)

Re: Expanding box - auto height....??

Posted: Tue Jun 10, 2014 11:51 am
by Celauran
Actually, src="//foo.bar.com" is perfectly valid, even preferable. It uses the same protocol as the current request, so you don't end up with 'insecure elements' notifications when requesting an asset over HTTP when using an HTTPS connection.