Transition on transform translate not working - css

Does anybody know how to animate the transition the right way? As you can see in the code, after a small delay the div has to move up. I couldn't get it to work.
Codepen:
http://codepen.io/thijs-webber/pen/jqgPrK
HTML:
<div class="test">
test
</div>
CSS:
.test{
background-color: lime;
width: 100px;
margin: 0 auto;
margin-top: 100px;
height: 100px;
padding: 10px;
text-align: center;
line-height: 100px;
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
transition: transform 1s ease-out;
-webkit-transition: transform 1s ease-out;
-moz-transition: transform 1s ease-out;
-ms-transition: transform 1s ease-out;
-o-transition: transform 1s ease-out;
transition-delay: 1s;
}

Using a trigger is one idea, but If you don't want any trigger, you just have to use CSS3 keyframes
Here's your code with it:
.test{
background-color: lime;
width: 100px;
margin: 0 auto;
margin-top: 100px;
height: 100px;
padding: 10px;
text-align: center;
line-height: 100px;
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
animation-name: moveUp;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 1s;
}
#keyframes moveUp {
0% {
transform: translate(0);
}
100% {
transform: translate(0, -100px);
}
}
<div class="test">
test
</div>
I added the necessary animations styles, such as name (used in the keyframes), how many times should this animation occur, the timing-function and the duration, respectively:
animation-name: moveUp;
animation-iteration-count: 1;
animation-timing-function: ease-out;
animation-duration: 1s;
I hope this helps!

It works, but due to there is no trigger, you can't observe its movement. When you loaded the page, transition had already been completed. If you want to observe transition, there should be a trigger like hover or you can use animation css method. In snippet hover is a trigger. As I said if you want it to work when page is opened, you can use animation.
.test{
background-color: lime;
width: 100px;
margin: 0 auto;
margin-top: 100px;
height: 100px;
padding: 10px;
text-align: center;
line-height: 100px;
transition: transform 1s ease-out;
-webkit-transition: transform 1s ease-out;
-moz-transition: transform 1s ease-out;
-ms-transition: transform 1s ease-out;
-o-transition: transform 1s ease-out;
}
.test:hover{
-moz-transform: translate(0, -100px);
-webkit-transform: translate(0, -100px);
-o-transform: translate(0, -100px);
-ms-transform: translate(0, -100px);
transform: translate(0, -100px);
}
<div class="test">
test
</div>

Related

Animation of Arrow with Click

i am absolute newbie and this is my first code:
.container_menu {
position: relative;
top: 0px;
left: 0px;
width: 25px;
height: 25px;
}
.container_menu .line-1 {
background-color: black;
width: 59%;
height: 2px;
position: absolute;
top: 50%;
left: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
.container_menu .line-2 {
background-color: black;
width: 59%;
height: 2px;
position: absolute;
top: 50%;
right: 0;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.3s ease 0s;
-moz-transition: all 0.3s ease 0s;
-o-transition: all 0.3s ease 0s;
transition: all 0.3s ease 0s;
}
.container_menu:hover .line-1 {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.container_menu:hover .line-2 {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
<div class="container_menu">
<div class="line-1"></div>
<div class="line-2"></div>
</div>
How could I have a animation with click (Maybe JS?) and not with hover?
I will use it in a menu of a website.
I think I must use a JS Code. But I don't know, how I could realize. Perhaps you can help me, many thanks.
Code from https://codepen.io/defaultdave/pen/baXLPQ
https://codepen.io/Tanded/pen/OqVBPE
<div class="container" onclick="fnc(this)">
<div class="line-1"></div>
<div class="line-2"></div>
</div>
function fnc(el){
el.classList.toggle("clicked");
}
add a small js function to toggle class and edit css to animate lines when they have clicked class instead of hover
&:hover -> &.clicked on line 53

CSS3 Floating ship animation

I am trying to make a floating effect animation. Basically the element will swing with an axis on its lower part, like in the image bellow:
http://1.bp.blogspot.com/-m7IuLfuaIC0/UGJGAikLXII/AAAAAAAAKis/N8NfMwdMExY/s1600/GANGORRA.jpg
I dont know how to settle the 2 movements, and also make it constant.
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-transform: rotateZ(-30deg);
-ms-transform: rotateZ(-30deg);
transform: rotateZ(-30deg);
-webkit-transform: rotateZ(30deg);
-ms-transform: rotateZ(30deg);
transform: rotateZ(30deg);
Is this what you want?
#ship
{
animation: swing 2s infinite ease;
background: green;
color: #fff;
text-align: center;
transform-origin: bottom center;
height: 100px;
line-height: 100px;
width: 100px;
}
#keyframes swing
{
0%{ transform: rotate(-10deg);}
50%{ transform: rotate(20deg);}
100%{ transform: rotate(-10deg);}
}
<div id="ship">SHIP</div>

IOS Safari transition transform not working

Whenever I seem to apply some code to let's say move a div for example using the latest iOS Safari browser it doesn't actually transition between the two rules set. I have tried changing to use other than percentage values but still to this day, I have never been able to get it to work when I use transition: transform; for any translate property applied.
I'm using the correct prefixes and checked support and should be working no problem.
http://caniuse.com/#search=transition
http://caniuse.com/#search=translate
JSFiddle
$('button').on('click', function() {
$('.mydiv').toggleClass('added-class');
});
.mydiv {
display: inline-block;
width: 100px;
height: 50px;
background-color: red;
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-o-transform: translateY(0);
-webkit-transform: translateY(0);
transform: translateY(0);
-moz-transition: transform 0.6s ease-out;
-o-transition: transform 0.6s ease-out;
-webkit-transition: transform 0.6s ease-out;
transition: transform 0.6s ease-out;
}
.added-class {
-moz-transform: translateY(100%);
-ms-transform: translateY(100%);
-o-transform: translateY(100%);
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="mydiv"></div>
<button type="button">Toggle class</button>
Old versions of iOS Safari support only vendor-prefixed properties and values for transition and transform, so you should use -webkit-transition: -webkit-transform instead -webkit-transition: transform:
JSFiddle
$('button').on('click', function() {
$('.mydiv').toggleClass('added-class');
});
.mydiv {
display: inline-block;
width: 100px;
height: 50px;
background-color: red;
-webkit-transform: translateY(0);
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-o-transform: translateY(0);
transform: translateY(0);
-webkit-transition: -webkit-transform 0.6s ease-out;
-moz-transition: transform 0.6s ease-out;
-o-transition: transform 0.6s ease-out;
transition: transform 0.6s ease-out;
}
.added-class {
-webkit-transform: translateY(100%);
-moz-transform: translateY(100%);
-ms-transform: translateY(100%);
-o-transform: translateY(100%);
transform: translateY(100%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="mydiv"></div>
<button type="button">Toggle class</button>

Card flipping by css transform, which properties need animation?

Demo
The core of the flipping animation is on transform: rotateY(180deg);. Of course transition is needed as well for animation. I copied the code from another site, which uses transition: all ...;.
For some reason, some properties (eg: height, width) must have no transition. But I don't know which properties are essential for flipping animation.
Anyone knows how I can change the line transition: all ...; to keep the flipping animation, while not affecting unrelated properties?
This page explains everything and has live demos. I've just needed a simple Google search. :)
http://desandro.github.io/3dtransforms/docs/card-flip.html
Apparently, the trick is to use
transition: transform 1s;
change the style when you :hover on parent
.card {
-moz-perspective: 600;
-webkit-perspective: 600;
perspective: 600;
position: relative;
height: 200px;
width: 200px;
}
.card .side {
overflow: hidden;
position: absolute;
top: 0;
left: 0;
width: inherit;
height: inherit;
-moz-box-shadow: 0 0 5px #888;
-webkit-box-shadow: 0 0 5px #888;
box-shadow: 0 0 5px #888;
-moz-transform-style: perserve-3d;
-webkit-transform-style: perserve-3d;
transform-style: perserve-3d;
-moz-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-transition: all 0.4s ease-in-out;
-o-transition: all 0.4s ease-in-out;
-webkit-transition: all 0.4s ease-in-out;
transition: all 0.4s ease-in-out;
}
.card .side.front {
z-index: 900;
-moz-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
.card:hover .side.front {
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.card .side.back {
z-index: 800;
-moz-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
}
.card:hover .side.back {
z-index: 800;
-moz-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
}
<article class="card">
<section class="side front">front</section>
<section class="side back">back</section>
</article>

CSS delay transition

The following CSS works fine, however I am trying to add 1 or 2 seconds delay to the flip back effect. When you hover it the '.back' is visible and then when you leave the area the '.front'. I would like to add a delay so that when you leave the area it takes one or two seconds before it goes back to '.front' Is that possible?
.panel {
width: 250px!important;
height: 250px;
margin: auto!important;
position: relative;
-webkit-perspective:1000px;
}
.card {
width: 100%!important;
height: 100%;
-o-transition: all .5s;
-ms-transition: all .5s;
-moz-transition: all .5s;
-webkit-transition: all .5s;
transition: all .5s;
-webkit-backface-visibility: hidden;
-ms-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
top: 0px;
left: 0px;
}
.front {
z-index: 2;
}
.back {
background-color:#fff;
z-index: 1;
-webkit-transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
-moz-transform: rotateY(-180deg);
transform: rotateY(-180deg);
transition-delay: 2s;
}
.back p{
margin-top: 90px;
font-size: 20px;
text-align:center;
}
.panel:hover .front {
z-index: 1;
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
-webkit-transition:-webkit-transform 1s;
transition:transform 1s;
}
.panel:hover .back {
z-index: 2;
-webkit-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
-moz-transform: rotateY(0deg);
transform: rotateY(0deg);
-webkit-transition:-webkit-transform 1s;
transition:transform 1s;
transition-delay: 2s;
}
HTML
<li class="panel"><img class="front card" src="{{image}}" /><div class="back card"><p>{{model.user.full_name}}</p></div></li>
Add the transition-delay to .card - fiddle
.card {
-o-transition: all .5s 2s;
-ms-transition: all .5s 2s;
-moz-transition: all .5s 2s;
-webkit-transition: all .5s 2s;
transition: all .5s 2s;
}
.panel .front {
transition: all 2s;
}
You have to put the effect on the element in order to have it transition back without hovering on it.

Resources