I've been trying out the summary and details list and can't find a way to make it auto collapse when the next in the list is clicked...
Here the code I have:
HTML:
<div class="content">
<header class="major">
<h2>Stuff I do</h2>
</header>
<p>Consequat sed ultricies rutrum. Sed adipiscing eu amet interdum lorem blandit vis ac commodo aliquet vulputate.</p>
<ul class="alt">
<li>
<details><summary><span class="icon major fa-camera-retro"></span>
<h3>List item 1</h3><p>Donec accumsan interdum nisi</p></summary>
<p>Aliquam ante ac id. Adipiscing interdum lorem praesent fusce pellentesque arcu feugiat. Consequat sed ultricies rutrum. Sed adipiscing eu amet interdum lorem blandit vis ac commodo aliquet integer vulputate phasellus lorem ipsum dolor lorem magna consequat sed etiam adipiscing interdum.</p></details>
</li>
<li>
<details><summary><span class="icon major fa-pencil"></span>
<h3>List item 2</h3><p>Donec accumsan interdum nisi</p></summary>
<p>Aliquam ante ac id. Adipiscing interdum lorem praesent fusce pellentesque arcu feugiat. Consequat sed ultricies rutrum. Sed adipiscing eu amet interdum lorem blandit vis ac commodo aliquet integer vulputate phasellus lorem ipsum dolor lorem magna consequat sed etiam adipiscing interdum.</p></details>
</li>
<li>
<details><summary><span class="icon major fa-code"></span>
<h3>list item 3</h3><p>Donec accumsan interdum nisi</p></summary>
<p>Aliquam ante ac id. Adipiscing interdum lorem praesent fusce pellentesque arcu feugiat. Consequat sed ultricies rutrum. Sed adipiscing eu amet interdum lorem blandit vis ac commodo aliquet integer vulputate phasellus lorem ipsum dolor lorem magna consequat sed etiam adipiscing interdum.</p></details>
</li>
<li>
<details><summary><span class="icon major fa-coffee"></span>
<h3>List item 4</h3><p>Donec accumsan interdum nisi</p></summary>
<p>Aliquam ante ac id. Adipiscing interdum lorem praesent fusce pellentesque arcu feugiat. Consequat sed ultricies rutrum. Sed adipiscing eu amet interdum lorem blandit vis ac commodo aliquet integer vulputate phasellus lorem ipsum dolor lorem magna consequat sed etiam adipiscing interdum.</p></details>
</li>
</ul>
</div>
CSS:
details summary::-webkit-details-marker {
display: none;}
summary:hover {
cursor: pointer;
color: #fff200;
}
So when 'list item 1' is opened and 'list item 3' is clicked I want item 1 to automatically collapse again. Help would be very much appreciated!
Idea
slideUp()
all paragraphs insideli
, so only headers are visible.slideUp()
all other items, andslideDown()
the clicked one.Implementation
Alter html to add clases so
jQuery
can reference them (class="click"
andclass="collapsable"
):jQuery onload:
Working fiddle: http://jsfiddle.net/2mbs4wxp/4/
EDIT
To solve the issue described in comment:
Chain the
animate({scrollTop...
to theslideDown()
event so your clicked div is scrolled to the top of the screen. You just need to alter your jQuery a bit:Working Fiddle: http://jsfiddle.net/2mbs4wxp/6/