2
I found several answers here, but for bootstrap 3. I even tried to adapt to 4 but without success.
I’m trying to make when I show one Ollapse hide the other and vice versa(I can’t use static "id" because it will have several categories added by the user so I’ll never know the id in question).
$(function () {
$('.overlay').on('click', function (e) {
var active = $( e.currentTarget );
$('.overlay').not(this).removeClass( 'active');
$('.overlay').not(this).removeClass( 'collapse');
$(this).addClass( 'active');
if (active.attr( 'aria-expanded') === 'true') {
$('.overlay').not(this).addClass( 'collapsed');
not(active).attr( 'aria-expanded') === 'true';
}
});
$('.title').on('click', function (e) {
var active = $( e.currentTarget );
$(this).next().addClass( 'active');
});
});
#categorias {padding: 80px 0;}
#categorias .categoria {position: relative;cursor: pointer;}
#categorias .categoria h2 {color: #fff;position: absolute;top: calc(50% - 2rem);width: 100%;text-align: center;z-index: 200;}
#categorias .categoria img {filter: brightness(0.5);transition: all 500ms;}
#categorias .categoria:hover img {filter: brightness(1);}
#categorias .categoria .overlay {width: 100%;height: 100%;display: block;position: absolute;top: 0;left: 0;transition: all 500ms;z-index: 100;}
#categorias .categoria:hover .overlay, #categorias .active {background: rgba(151, 2, 2, 0.8);}
#categorias .categoria .divider {width: 70%;height: 0;display: block;position: absolute;bottom: 0;text-align: center;transition: all 500ms;z-index: 200;margin: 0 17%;background: #fff;}
#categorias .categoria:hover .divider {height: 17px;}
#categorias ul {padding: 0;margin: 0;}
#categorias ul li {list-style: none;}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<section id="categorias">
<div class="row no-gutters" id="list-categorias">
<div class="col-6 col-md-3 categoria" id="grelhas_head">
<img src="https://i.imgur.com/pQcVh9h.png" class="img-fluid">
<h2 class="title" data-toggle="collapse" data-target="#grelhas" role="button" aria-expanded="false" aria-controls="grelhas">grelhas argentinas</h2>
<span class="overlay" data-toggle="collapse" data-target="#grelhas" role="button" aria-expanded="false" aria-controls="grelhas"></span>
<span class="divider"></span>
</div>
<div class="col-6 col-md-3 categoria" id="grelhas2_head">
<img src="https://i.imgur.com/pQcVh9h.png" class="img-fluid">
<h2 class="title" data-toggle="collapse" data-target="#multiCollapseExample2" role="button" aria-expanded="false" aria-controls="multiCollapseExample2">grelhas argentinas</h2>
<span class="overlay" data-toggle="collapse" data-target="#multiCollapseExample2" role="button" aria-expanded="false" aria-controls="multiCollapseExample2"></span>
<span class="divider"></span>
</div>
</div>
<div class="row no-gutters">
<div class="col">
<div class="collapse" id="grelhas" aria-labelledby="grelhas_head" data-parent="#list-categorias">
<div class="card card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
</div>
<div class="col">
<div class="collapse" id="multiCollapseExample2" aria-labelledby="grelhas2_head" data-parent="#list-categorias">
<div class="card card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
</div>
</div>
</section>
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
I understand what you did and it really turned out really good. But what I want needs to be a little different: The idea itself is the same, but for each category accordeon should appear in the same place. As in the example: https://codepen.io/anon/pen/PXWePX
– Lucas Granvilla
@Lucas has now become clearer, I will try to adjust this template to see if to save it rss
– hugocsl
@Lucas was very quiet to adapt, even I did not believe it was so easy rss, run the code there you will see that now the description always opens in the same place for all items
– hugocsl
that ai boss! thanks again for the help! always helping me!!
– Lucas Granvilla
@Lucas slow, but try to see why the code doesn’t work, I don’t know anything about JS, but who doesn’t have a cat dog :D
– hugocsl
was very good! do not stress!
– Lucas Granvilla
Can you take a look at this code? When you leave Hover it has an effect that you shouldn’t have. Thank you. https://codepen.io/anon/pen/wRgLVR
– Lucas Granvilla
@Luke speaks young! Boy to with the answer in hand, but not to explain you by the comment because I have to put code here etc. And there on the page when I refresh add everything. There’s a way you can open up a question and I’ll give you the answer in no time. I made this animated gif to help you show the problem https://imgur.com/a/xmN9uHH but don’t forget to include your code in the question tb
– hugocsl
Done: https://answall.com/questions/352459/hover-com-mix-blend-multipy
– Lucas Granvilla