When clicking on a specific header, I want only one chevron to rotate instead of all the chevrons rotating. I am currently unsure how to specify which chevron should rotate individually. My project is in ASP.NET MVC 5 and I am using razor view to loop through a list.
Index
@{
foreach (var item in Model)
{
<div class="accordion">
<a href="#"><h4>@item.Title</h4><i class="fa fa-chevron-right rotate"></i></a>
</div>
<div class="accordion-desc">
<h3>@Resource.AccordionProjectLead</h3>
<h4>Kay Wiberg</h4>
<h3>@Resource.AccordionDescription</h3>
<p>
@item.Description
<p>
<div class ="link">
<a href="@item.Url">@Resource.AccordionGoTo</a>
</div>
</div>
}
}
CSS for the rotating chevron
.rotate {
-moz-transition: all 0.1s linear;
-webkit-transition: all 0.1s linear;
transition: all 0.1s linear;
}
.rotate.down {
-moz-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
JS for accordion and chevron
$(document).ready(function() {
$(".accordion-desc").fadeOut(0);
$(".accordion").click(function() {
$(".accordion-desc").not($(this).next()).slideUp('fast');
$(this).next().slideToggle(400);
});
});
$(".accordion").click(function() {
$(".rotate").toggleClass("down");
});
from the browser:
<div class="container">
<div class="accordion">
<a href="#">
<h4>Test Site</h4><i class="fa fa-chevron-right rotate down"></i></a>
</div>
<div class="accordion-desc" style="display: none;">
<h3>Projektledare</h3>
<h4>Kay Wiberg</h4>
<h3>Beskrivning</h3>
<p>
</p>
<div class="link">
<a href="">Gå till</a>
</div>
</div>
<div class="accordion">
<a href="#">
<h4>Test site 2</h4><i class="fa fa-chevron-right rotate"></i></a>
</div>
<div class="accordion-desc" style="display: none;">
<h3>Projektledare</h3>
<h4>Kay Wiberg</h4>
<h3>Beskrivning</h3>
<p>
Somthindsyvgds
</p>
<div class="link">
<a href="">Gå till</a>
</div>
</div>
</div>