I use the Bootstrap carousel and I need to modify the margin-top of a title, but when the content div is: hidden, I can not get the height of the text with jquery. Here is 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>