I wanted to expand <div>
, but I can not. Where am I going wrong?
In principle this will be, but I want to make a screen with 100% width
with this effect, expanding and returning with another click.
Expand box with CSS transitions
<div class="expandir-boxes">
<div class="expandir-box">
<h2>Box 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut euismod eget turpis quis convallis.</p>
</div>
<div class="expandir-box">
<h2>Box 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut euismod eget turpis quis convallis.</p>
</div>
<div class="expandir-box">
<h2>Box 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut euismod eget turpis quis convallis.</p>
</div>
<div class="expandir-box">
<h2>Box 4</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut euismod eget turpis quis convallis.</p>
</div>
<div class="expandir-box">
<h2>Box 5</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut euismod eget turpis quis convallis.</p>
</div>
<div class="expandir-box">
<h2>Box 6</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut euismod eget turpis quis convallis.?</p>
</div>
</div>
</div>
CSS:
.expandir-boxes {
position: relative;
}
.expandir-box {
width: 30%;
height: 130px;
float: left;
margin: 0 3% 20px 0;
border: 1px solid #999;
border-radius: 12px;
padding: 10px;
box-sizing: border-box;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-o-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
&.open {
border-color: #dd0000;
width: 96%;
height: 180px;
margin: 0;
}
&.out {
width: 0;
height: 0;
overflow: hidden;
border: none;
padding: 0;
margin: 0;
opacity: 0;
}
}
Javascript:
$(document).ready(function() {
$('.expandir-box').click(function(e) {
alert("Funcionou");
if($(this).hasClass('open')) {
$('.expandir-box.out').not($(this)).removeClass('out');
$(this).removeClass('open');
}
else {
$('.expandir-box').not($(this)).addClass('out');
$(this).addClass('open');
}
});
});