Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make transition smooth?

Tags:

css

I am trying to create two containers which will be placed at the same position. When I mouse hover on top one that should affected with some transition and bottom/second div content should display. I tried this here

Everything is fine.But it is giving some flicker effect when i mouse hover on it. How to make it smooth transition? I am using following snippet for transition effect

.box:hover{
    -webkit-transform:  rotate(100deg) scale(1);
    -webkit-transform-origin:bottom right;
}
like image 401
Mihir Avatar asked Mar 04 '14 13:03

Mihir


People also ask

How do you do a smooth TikTok transition?

Don't move any objects in the background, keep the same lighting, and also keep yourself in the same position. This will create the smoothest transformations. To do that, you may want to mark where you stand and use a tripod so the angle doesn't change if it's a wide shot.

How do I make transitions smoother in CSS?

With CSS3 we can specify how an element changes by just describing its current and target states. CSS3 will create a smooth transition between these states by applying a cubic Bézier curve and gradually change the element appearance.


1 Answers

Use CSS transition property to make the animation smoother

.box {
    height:150px;
    width:200px;
    background:indianred;
    position:absolute;
    top:20%;
    left:40%;
    -webkit-transition: all .5s;
    -moz-transition: all .5s;
    transition: all .5s;
}

Demo


Note: You are using -webkit specific proprietary property, so inorder to make it cross browser compatible, use

Demo

.box {
    height:150px;
    width:200px;
    background:indianred;
    position:absolute;
    top:20%;
    left:40%;
    -webkit-transition: all .5s;
    -moz-transition: all .5s;
    transition: all .5s;
}
.box1 {
    height:150px;
    width:200px;
    border:1px solid black;
    position:absolute;
    top:20%;
    left:40%;
    z-index:-100;
}
.box:hover {
    -webkit-transform: rotate(100deg) scale(1);
    -webkit-transform-origin:bottom right;
     -moz-transform: rotate(100deg) scale(1);
    -moz-transform-origin:bottom right;
     transform: rotate(100deg) scale(1);
    transform-origin:bottom right;
}

Well, you asked for a solution in your comment and I provided a solution for that as well..

<div class='box1'>
    <div class='box'></div>
    <p class="innerText">This is content</p>
</div>

.box {
    height:150px;
    width:200px;
    background:indianred;
    position:absolute;
    top:0%;
    left:0%;
    -webkit-transition: all .5s;
    -moz-transition: all .5s;
    transition: all .5s;
}
.box1 {
    height:150px;
    width:200px;
    border:1px solid black;
    position:absolute;
    top:20%;
    left:40%;
    z-index:-100;
}
.box1:hover .box {
    -webkit-transform: rotate(100deg) scale(1);
    -webkit-transform-origin:bottom right;
     -moz-transform: rotate(100deg) scale(1);
    -moz-transform-origin:bottom right;
     transform: rotate(100deg) scale(1);
    transform-origin:bottom right;
}

Demo


The difference between my code and your code is that first, you missed a position: relative; container around an element having position: absolute; which will always bring you undesired results.

Second mistake was the markup, if you are looking to hide an element, you should nest an overlaying element rather than placing it outside the element you want to hide.

So in my example, I shifted the overlaying element in the div, and the main part comes here, you used :hover on the same element you were transforming, and thus it was collapsing for no reason, instead, in my selector, I am triggering the animation on :hover of the parent element, and not the element it self which is to be transformed.

like image 180
Mr. Alien Avatar answered Oct 10 '22 06:10

Mr. Alien