CSS3 회전 애니메이션


244
<img class="image" src="" alt="" width="120" height="120">

이 애니메이션 이미지를 작동시킬 수 없으며 360도 회전해야합니다.

나는 여전히 머물러 있기 때문에 아래 CSS에 문제가 있다고 생각합니다.

.image {
    float: left;
    margin: 0 auto;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120px;
    height: 120px;
    margin-top: -60px;
    margin-left: -60px;

    -webkit-animation-name: spin;
    -webkit-animation-duration: 4000ms;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;

    -moz-animation-name: spin;
    -moz-animation-duration: 4000ms;
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: linear;

    -ms-animation-name: spin;
    -ms-animation-duration: 4000ms;
    -ms-animation-iteration-count: infinite;
    -ms-animation-timing-function: linear;

    animation-name: spin;
    animation-duration: 4000ms;
    animation-iteration-count: infinite;
    animation-timing-function: linear;

    @-ms-keyframes spin { 
        from { 
            -ms-transform: rotate(0deg); 
        } to { 
            -ms-transform: rotate(360deg); 
        }
    }
    @-moz-keyframes spin { 
        from { 
            -moz-transform: rotate(0deg); 
        } to { 
            -moz-transform: rotate(360deg); 
        }
    }
    @-webkit-keyframes spin { 
        from { 
            -webkit-transform: rotate(0deg); 
        } to { 
            -webkit-transform: rotate(360deg); 
        }
    }
    @keyframes spin { 
        from { 
            transform: rotate(0deg); 
        } to { 
            transform: rotate(360deg); 
        }
    }
}

답변:


520

여기 데모가 있습니다. 올바른 애니메이션 CSS :

.image {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120px;
    height: 120px;
    margin:-60px 0 0 -60px;
    -webkit-animation:spin 4s linear infinite;
    -moz-animation:spin 4s linear infinite;
    animation:spin 4s linear infinite;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
<img class="image" src="http://i.stack.imgur.com/pC1Tv.jpg" alt="" width="120" height="120">


코드에 대한 참고 사항 :

  1. .image규칙 내부에 키 프레임을 중첩 시켰는데 잘못되었습니다.
  2. float:left 절대적으로 배치 된 요소에서는 작동하지 않습니다
  3. caniuse 살펴보기 : IE10에는 -ms-접두사 가 필요하지 않습니다.

13
누군가가 자신의 코드로 이것을 시도하면 : 하단의 @ 섹션을 잊어 버려라
— Jack M.

Hello 5 초 후에 애니메이션 무한 회전을 멈출 수 있습니까?
— MD Ashik

16
애니메이션을 실행할 때 물이 거의 빠지지 않았습니다.
— Razgriz

" float:left won't work on absolutely positioned elements", 디스플레이와 비슷한 최소 크기로 축소합니다 : inline-block does
— gregn3

32

나는 당신과 같은 것을 사용하여 회전하는 이미지를 가지고 있습니다 :

.knoop1 img{
    position:absolute;
    width:114px;
    height:114px;
    top:400px;
    margin:0 auto;
    margin-left:-195px;
    z-index:0;

    -webkit-transition-duration: 0.8s;
    -moz-transition-duration: 0.8s;
    -o-transition-duration: 0.8s;
    transition-duration: 0.8s;

    -webkit-transition-property: -webkit-transform;
    -moz-transition-property: -moz-transform;
    -o-transition-property: -o-transform;
     transition-property: transform;

     overflow:hidden;
}

.knoop1:hover img{
    -webkit-transform:rotate(360deg);
    -moz-transform:rotate(360deg); 
    -o-transform:rotate(360deg);
}

1
추가 : transform:rotate(360deg);IE 용
— Dusty

3
깨진 웹 사이트 링크에서 현지 예를 선택하십시오.
— evolutionxbox

링크가 끊어졌습니다.
— Markus Bucher

30

360도 회전을 달성하기 위해 다음은 작업 솔루션 입니다.

HTML :

<img class="image" src="your-image.png">

CSS :

.image {
    overflow: hidden;
    transition-duration: 0.8s;
    transition-property: transform;
}
.image:hover {
    transform: rotate(360deg);
    -webkit-transform: rotate(360deg);
}

이미지를 가리키면 360도 회전 효과가 나타납니다.

추신 : -webkit-크롬 및 기타 웹킷 브라우저에서 작동 하도록 확장 프로그램을 추가하십시오 . 당신은 웹킷에 대한 업데이트 된 바이올린을 확인할 수 있습니다 여기에


Fiddle은 작동하지 않습니다. Chrome 관리자는 CSS, 특히 "변환"및 "전환 속성"을 좋아하지 않습니다. 이런.
— Just Plain High

1
-webkit-tranform이를 위해 작동 하려면를 추가해야합니다 . 다음은 업데이트 된 바이올린입니다. jsfiddle.net/sELBM/172-@JustPlainHigh –
— Nitesh

1
2017 : 이것은 매우 잘 지원되며 무한 회전이 아닌 기본 방법입니다. -webkit-접두사는 더 이상 필요하지 않으며 안전하게 제거 할 수 있습니다. 브라우저 지원 : caniuse.com/#search=transforms
— Alph.Dev

2

이미지를 뒤집으려면 사용할 수 있습니다.

.image{
    width: 100%;
    -webkit-animation:spin 3s linear infinite;
    -moz-animation:spin 3s linear infinite;
    animation:spin 3s linear infinite;
}
@-moz-keyframes spin { 50% { -moz-transform: rotateY(90deg); } }
@-webkit-keyframes spin { 50% { -webkit-transform: rotateY(90deg); } }
@keyframes spin { 50% { -webkit-transform: rotateY(90deg); transform:rotateY(90deg); } }

0

.image {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120px;
    height: 120px;
    margin:-60px 0 0 -60px;
    -webkit-animation:spin 4s linear infinite;
    -moz-animation:spin 4s linear infinite;
    animation:spin 4s linear infinite;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
<img class="image" src="http://i.stack.imgur.com/pC1Tv.jpg" alt="" width="120" height="120">


0

이 쉬운 시도

 
 .btn-circle span {
     top: 0;
   
      position: absolute;
     font-size: 18px;
       text-align: center;
    text-decoration: none;
      -webkit-animation:spin 4s linear infinite;
    -moz-animation:spin 4s linear infinite;
    animation:spin 4s linear infinite;
}

.btn-circle span :hover {
 color :silver;
}


/* rotate 360 key for refresh btn */
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } } 
 <button type="button" class="btn btn-success btn-circle" ><span class="glyphicon">&#x21bb;</span></button>


-6

여기 이것이 당신을 도울 것입니다

아래의 jsfiddle 링크는 이미지 회전 방법을 이해하는 데 도움이됩니다. 시계 다이얼을 돌리기 위해 동일한 것을 사용했습니다.

http://jsfiddle.net/xw89p/

var rotation = function (){
   $("#image").rotate({
      angle:0, 
      animateTo:360, 
      callback: rotation,
      easing: function (x,t,b,c,d){       
          return c*(t/d)+b;
      }
   });
}
rotation();

• t : 현재 시간

• b : 시작 값,

• c : 가치 변화

• d : 기간,

• x : 미사용

여유 없음 (선형 여유) : function (x, t, b, c, d) {return b + (t / d) * c; }


2
바이올린에서와 같이 조금 더 많은 정보를 제공하면이 답변을 찬성합니다. 나는 또한 당신은 내가 모두 같았다 때문에 이것은 jQuery 플러그인을 언급한다고 생각한다 "나는 jQuery를이 할 수 몰랐어요! ^ _ ^ 바이올린에서 보이는 오 대기 ... U_U"
— 그냥 일반 고

2
x, t, b, c, d 변수에 대한 설명 (피들에서와 같이)은 OP에서 요청한 CSS 솔루션은 아니지만 매우 간단하고 효과적인 jQuery 플러그인 솔루션임을 분명히 밝힙니다. )
— Just Plain High

3
공감. OP는 자바 스크립트 솔루션을 요청하지 않았으며 특히 jQuery 플러그인은 요청하지 않았습니다. 요구되는 것을 고수하십시오.
— TheCarver
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.