gwooden_코린이

html + CSS 애니메이션 본문

프론트엔드/html

html + CSS 애니메이션

gwooden22 2022. 12. 19. 15:11
728x90
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="css/style4.css">
</head>
<body>
  <div>
    
  </div>
</body>
</html>
div {
  width: 50px;
  height: 50px;
  background-color: blue;
  position: relative;

  animation-name: ani;
  /*animation-duration: 3s;  몇 초 동안 진행할지 */

  /* animation-timing-function: ease-in; */

 /*  animation-delay: 3s; 이미지 시작 딜레이 */

  /* animation-iteration-count: 2; 반복 횟수 (무한반복은 infinite) */

  /*animation-direction: alternate;  역방향 재생 (최소 2번이상 반복 재생 필요) */
  /* reverse는 시작자체를 역방향으로 시작 */


  /* animation:  ani 3s 1s ease-in infinite alternate;  <--- 한 줄에 코드 입력 가능*/
  animation:  ani 3s 1s ease-in alternate;

  animation-fill-mode: both;

}

div:hover { /* 커서를 이용한 효과 */

  animation-play-state: paused;

}

/* @keyframes ani {
  from {
    left: 0;
    background-color: blue;
  }
  to {
    left: 200px;
    background-color: red;
  }
} */


/* 위 키프레임 보다 더 세분화해서 할 수 있음 */

@keyframes ani {
  0% {
    left: 0;
    background-color: blue;
  }

  50% {
    left: 200px;
    background-color: red;
  }

  100% {
    left: 400px;
    background-color: red;
  }
}

▶ 사각형 모형 좌우/위 아래로 연속 이동해보기

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="css/style5.css">
</head>
<body>
  <div>
    
  </div>
</body>
</html>
div {
  width: 50px;
  height: 50px;
  background-color: blue;
  position: relative;

  animation: ani;
  animation-duration: 3s;


}




div:hover { /* 커서를 이용한 효과 */

  animation-play-state: paused;
}

@keyframes ani {
  0% {
    left: 0;
    top: 0;
  }

  25% {
    left: 200px;
    top: 0;
    background-color: blueviolet;
  }

  50% {
    left: 200px;
    top: 200px;
    background-color: yellow;
  }

  75% {
    left: 0;
    top: 200px;
    background-color: gray;
  }

  100% {
    left: 0;
    top: 0;
    background-color: red;
  }
}


 마우스 커서 올렸을때 색상이 천천히 바뀌게 하기

div {
  width: 50px;
  height: 50px;
  background-color: blue;
  position: relative;

  transition: all 2s;
}

div:hover  {
  /* background-color: red; */
  opacity: 0.5;
}
728x90
Comments