So I need to find the height of an element to correctly transition it in. My problem is that this element does not have a height initially because it would mess with my website layout.
This value changes based on the device used to view the site and it's the height of my text box.
It might be possible to load the page without hiding the text and then getting the height and hiding it with javascript, but I believe that wouldn't be an ideal solution at all.
My goal is that no matter if the page is image only or if the text is displayed, in both cases everything should be vertically and horizontally centered.
document.getElementById("intro-img").onclick = function() {
$("#intro-img").toggleClass('show');
$("#text").toggleClass('show');
}
.full-size {
height: 100vh;
overflow: hidden;
}
.title-img {
max-height: 250px;
}
#intro-img {
cursor: pointer;
height: 250px;
transition: all 0.75s linear;
}
#intro-img.show {
height: 125px;
}
#text {
opacity: 0;
height: 0;
transition: all 0.75s linear;
overflow: hidden;
}
#text.show {
opacity: 1;
height: 105px; /* I need this value set based on vw */
}
.container {
margin-left: auto !important;
margin-right: auto !important;
}
.row {
width: 100%;
margin-left: auto !important;
margin-right: auto !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="container full-size valign-wrapper">
<div class="row">
<div class="col s12 center-align">
<img id="intro-img" class="responsive-img title-img" src="http://undeadleech.com/img/UndeadLeech_x3_round.png">
</div>
<div id="text" class="col s12 center-align">
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et
ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</div>
</div>
</div>
</body>