Expanding box - auto height....??

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Expanding box - auto height....??

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post by simonmlewis »

Don't worry, I found one I recall doing once before - with 'bootstrap'. :)
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post by Celauran »

You have an unmatched style tag and a src="ttp://etc..."
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

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

Post 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.
:)
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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.
Post Reply