본문 바로가기

Frontend/jQuery

JS jQuery (part. 33) - 사용자 정의 효과

개발자가 원하는 방향으로 효과를 만들고 싶을 때 사용하는 메서드

 

  • animate( ) : 사용자 지정 효과를 생성한다
  1. $(selector).animate(object);
  2. $(selector).animate(object, speed);
  3. $(selector).animate(object, speed, easing);
  4. $(selector).animate(object, speed, easing, callback);

animate( ) 메서드의 첫 번째 매개변수인 객체에 입력할 수 있는 속성

  • opacity
  • height
  • top
  • width
  • left
  • margin
  • right
  • padding
  • bottom

<style>
  div {
    width: 50px;
    height: 50px;
    background-color: orange;
    position: relative;
  }
</style>

<body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</body>

 

$(function () {
  $('div').hover(function () {
    $(this).animate({
        left: 500,
        top: 100
      }, 'slow');
    }, function () {
      $(this).animate({
        left: 0,
        top: 0
      }, 'slow')
  });
});