애니메이션 (background-image)

/**
 * @param SECTION {number}
 * @param WIDTH {number}
 * @param TIME {number}
 * @param DELAY {number}
 * @param STOP {number}
 */
$.fn.aniJin = function (SECTION, WIDTH, TIME, DELAY, STOP){
  TIME = TIME || 200;
  var num = 0;
  var playing = null;
  var $this = $(this);

  var repeat = setInterval(ani, TIME);
  function ani() {
    var bpx = parseInt($this.css("backgroundPositionX")); //백그라운드의 현재 위치값
    $this.css({
      backgroundPositionX: "-=" + SECTION
    }); //반복되는 구간 만큼 백그라운드 이동

    if (bpx <= -(WIDTH-SECTION*2)) {
      $this.css({
        backgroundPositionX: 0
      });

      clearInterval(repeat);

      setTimeout(function(){
        if (playing === null) {
          repeat = setInterval(ani, TIME);
        } else {
          $('.ani_heartbeat').fadeOut(500);
        }
      }, DELAY);
      num ++;
    }
    if (num === STOP) {playing = false;}
  }
};
jinnnh's profile image

jinnnh

2017-02-20 11:00

Read more posts by this author