css - Smooth mouse-out animation -


i have diamond shaped div spins 360 degrees around own axis on hover using css animation.

i can't work out how ensure smooth going original state when not hovering anymore?

so far "jumps" when diamond in middle of turn. smooth. possible css animations? if not, maybe js?

.dn-diamond {    display: inline-block;    width: 100px;    height: 100px;    background: #000;    transform: rotate(-45deg);    margin: 50px;    overflow: hidden;  }  .dn-diamond:hover {    animation: spin 3s infinite linear;  }  @keyframes spin {    { transform: rotatey(0deg) rotate(-45deg); }      { transform: rotatey(360deg) rotate(-45deg); }  }
<div class="dn-diamond">

here jsfiddle

i trying use transition not keep original transformed shape of (it went being square, not diamond).

you should use transitions this. allow keep transition smooth when mouse moves out of element.

example :

.dn-diamond {    display: inline-block;    width: 100px;    height: 100px;    background: #000;    transform: rotatey(0deg) rotatez(-45deg);    transition: transform 3s linear;    margin: 50px;    overflow: hidden;  }  .dn-diamond:hover {    transform: rotatey(360deg) rotatez(-45deg);  }
<div class="dn-diamond">


you can control speed of transition when cursor moves out of element setting transition property on normal , hover state.

example :

.dn-diamond {    display: inline-block;    width: 100px;    height: 100px;    background: #000;    transform: rotatey(0deg) rotatez(-45deg);    transition: transform 0.5s linear;    margin: 50px;    overflow: hidden;  }  .dn-diamond:hover {    transform: rotatey(360deg) rotatez(-45deg);    transition: transform 3s linear;  }
<div class="dn-diamond">

note in above demos vendor prefixes aren't included. check caniuse know vendor prefixes need according browsers want support.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -