Animating / revealing content from the center

I'm trying to make a circular div expand from the center of the div to show the content inside. The content inside should not be affected by the resizing of the outer div.

See the jsfiddle here: http://jsfiddle.net/tim_m/22bnvLnn/3/

The problem with the above example is that the circle is expanding from the top left, not the middle. The content inside is beautiful. Using transform: scale () will make the content small, but should be specified and not scaled up during animation.

EDIT - Fabio's jsfiddle led me to this, which is the closest I'm looking for: http://jsfiddle.net/tim_m/wwonzr0u/2/ . The only problem is that the content seems to swell slightly during animation.

Here's my sample code:

<div class="circle">
    <div class="content">Content</div>
</div>

      

CSS

body {
    padding: 20px;
}

.button {
    border: 1px solid black;
    width: 100px;
    height: 20px;
    text-align: center;
}
.circle,.content {
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 2s ease-in-out;
    -ms-transition: all 2s ease-in-out;
    transition: all 2s ease-in-out;
}

.circle {    
    background: rgba( 99, 99, 99, 0.8 );
    border-radius: 100%;
    color: white;
    text-align: center;
    font-family: sans-serif;
    padding: 20px;
    overflow: hidden;
    width: 100px;
    height: 100px;
    line-height: 400px;
    position: absolute;
    left: 20%;
    top: 20%;
}

.circle.show {
    width: 400px;
    height: 400px;    
    vertical-align: middle;
}

.content {
    width: 400px;
    height: 400px;
    position: absolute;
}

      

+3


source to share


2 answers


I think this does what you want:

.circle {
    ...
    margin-top: 150px;
    margin-left: 150px; 
}

.circle.show {
    width: 400px;
    height: 400px;    
    margin: 0;
}

.content {
    line-height: 100px;    
    position: absolute; 
    width: 100px;
}

.show .content {
    line-height: 400px;
    width: 400px;
}

      



To keep the circle in the same position, I added a margin that decreases as the circle grows. The line height and .content width keep the text centered as the element grows.

Updated JSFiddle

+2


source


You made me sweat with this, but try changing your CSS to this:

body {
    padding: 20px;
}
.button {
    border: 1px solid black;
    width: 100px;
    height: 20px;
    text-align: center;
}
.circle, .content {
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -o-transition: all 2s ease-in-out;
    -ms-transition: all 2s ease-in-out;
    transition: all 2s ease-in-out;
}
.circle {
    background: rgba(99, 99, 99, 0.8);
    border-radius: 100%;
    color: white;
    text-align: center;
    font-family: sans-serif;
    padding: 20px;
    overflow: hidden;
    width: 100px;
    height: 100px;
    line-height: 10px;
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -o-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
    position: relative;
    left: 200px;
    top: 200px;
}
.circle.show {
    -webkit-transform: scale(3);
    -moz-transform: scale(3);
    -o-transform: scale(3);
    -ms-transform: scale(3);
    transform: scale(3);
    z-index:0;
}
.content {
    position: relative;
    transform: translateY(-50%);
    -webkit-transform:translateY(-50%);
    top:50%;
    color:#fff;
    z-index:1;
}
.show .content {
    transform: scale(1);
}

      



See fiddle here

0


source







All Articles