1
I use Bootstrap Carousel and need to modify the margin-top of a title, but when the content div is :Hidden, I cannot get the text height with jquery.
Follows the code:
$(document).ready(function () {
$('.slogan').each(function () {
var id = $(this).attr("id");
var margin = ($('#' + id).height()/2) - ($('#' + id + ' b').height()/2);
$('#' + id + ' h1').css('margin-top', margin);
});
});
#bg-img-1{
background-image: url("../img/pessoas-efeito.png")!important;
background-repeat: no-repeat;
height: 297px;
background-size: 100% auto;
}
#bg-img-2{
background-image: url("../img/familia-feliz.jpg") !important;
background-repeat: no-repeat;
background-size: 100%;
}
<div id="carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel" data-slide-to="0" class="active"></li>
<li data-target="#carousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<div id="bg-img-1" class="slogan">
<div class="container">
<h1 class="text-center text-slogan">
<b>
asdfasdfasdfasdffasdf
</b>
</h1>
</div>
</div>
</div>
<div class="item">
<div id="bg-img-2" class="slogan">
<div class="container">
<h1 class="text-center text-slogan">
<b>
lorem ipsum Lorem ipsum dolor sit amet <br>
asfasfasdf
</b>
</h1>
</div>
</div>
</div>
</div>
</div>
It is not possible to know the height of elements with
display: none;
.– Sergio
Is there any other way? @Sergio
– Murilo Souza
What effect do you want to make?
– Sergio
The text is in the middle vertically of the image. @Sergio
– Murilo Souza