taenykim / web-graphics-playground

๐ŸŽก ์›น ๊ทธ๋ž˜ํ”ฝ์Šค ๋†€์ดํ„ฐ
3 stars 1 forks source link

animeJS #4

Open taenykim opened 2 years ago

taenykim commented 2 years ago

https://animejs.com/documentation/

taenykim commented 2 years ago

์†์„ฑ

API

๐Ÿ‘ relative

ํ•ด๋‹น ๊ฐ’๋งŒํผ ์ด๋™ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ํ•ด๋‹น ๊ฐ’์œผ๋กœ ์ด๋™ํ•˜๋Š” ๊ฒƒ ISSUE resolve

anime({
  targets: ".el.relative-values",
  translateX: {
    value: "*=2.5", // 100px * 2.5 = '250px'
    duration: 1000,
  },
  width: {
    value: "-=20px", // 28 - 20 = '8px'
    duration: 1800,
    easing: "easeInOutSine",
  },
  rotate: {
    value: "+=2turn", // 0 + 2 = '2turn'
    duration: 1800,
    easing: "easeInOutSine",
  },
  direction: "alternate",
});

- ์ƒ๋Œ€๊ฐ’์œผ๋กœ value๋ฅผ ์ ์–ด์ฃผ๋ฉด ์ƒ๋Œ€์ ์œผ๋กœ ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
taenykim commented 2 years ago

Object animation

var logEl = document.querySelector('.battery-log');

var battery = {
  charged: '0%',
  cycles: 120
}

anime({
  targets: battery,
  charged: '100%',
  cycles: 130,
  round: 1,
  easing: 'linear',
  update: function() {
    logEl.innerHTML = JSON.stringify(battery);
  }
});
  1. targets์— ์—˜๋ฆฌ๋จผํŠธ๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ Object๊ฐ€ ๋“ค์–ด๊ฐ
  2. Object์˜ ํ”„๋กœํผํ‹ฐ๊ฐ€ anime ํ”„๋กœํผํ‹ฐ๋กœ ๋“ค์–ด๊ฐ (dest)
taenykim commented 2 years ago

svg

taenykim commented 2 years ago

specific property

anime({
  targets: ".specific-prop-params-demo",
  translateX: {
    value: 250,
    duration: 800,
  },
  rotate: {
    value: 360,
    duration: 1800,
    easing: "easeInOutSine",
  },
  scale: {
    value: 2,
    duration: 1600,
    delay: 1000,
    easing: "easeInOutQuart",
  },
  delay: 3000, // All properties except 'scale' inherit 250ms delay
});

๋งŒ์•ฝ ์ด๋Ÿฐ ํ˜•ํƒœ์ด๋ฉด ๊ณตํ†ต delay๋Š” scale ์™ธ ๋ชจ๋“  ์†์„ฑ์— ์ ์šฉ๋˜๊ณ , scale์€ 1000์œผ๋กœ ๊ฐœ์ธ ์†์„ฑ์œผ๋กœ ์ ์šฉ๋œ๋‹ค.

taenykim commented 2 years ago

function based parameters

anime({
  targets: '.function-based-params-demo .el',
  translateX: 270,
  direction: 'alternate',
  loop: true,
  delay: function(el, i, l) {
    return i * 100;
  },
  endDelay: function(el, i, l) {
    return (l - i) * 100;
  }
});

์š”๋ ‡๊ฒŒ ํ•จ์ˆ˜๋กœ๋„ ์ž‘์„ฑ๊ฐ€๋Šฅ, target๊ณผ, index, total length ์— ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค

function based values

anime({
  targets: ".function-based-values-demo .el",
  translateX: (el: HTMLElement) => {
    return el.getAttribute("data-x");
  },
  translateY: (el: HTMLElement, i: number) => {
    return 50 + -50 * i;
  },
  scale: (el: HTMLElement, i: number, l: number) => {
    return l - i + 0.25;
  },
  rotate: () => {
    return anime.random(-360, 360);
  },
  borderRadius: () => {
    return ["50%", anime.random(10, 35) + "%"];
  },
  duration: () => {
    return anime.random(1200, 1800);
  },
  delay: () => {
    return anime.random(0, 400);
  },
  direction: "alternate",
  loop: true,
});
taenykim commented 2 years ago

๐Ÿ•น timeline, add (Method)

var colorsExamples = anime.timeline({
  endDelay: 1000,
  easing: 'easeInOutQuad',
  direction: 'alternate',
  loop: true
})
.add({ targets: '.color-hex',  background: '#FFF' }, 0)
.add({ targets: '.color-rgb',  background: 'rgb(255,255,255)' }, 0)
.add({ targets: '.color-hsl',  background: 'hsl(0, 100%, 100%)' }, 0)
.add({ targets: '.color-rgba', background: 'rgba(255,255,255, .2)' }, 0)
.add({ targets: '.color-hsla', background: 'hsla(0, 100%, 100%, .2)' }, 0)
.add({ targets: '.colors-demo .el', translateX: 270 }, 0);

offset

.add({
  targets: '.offsets-demo .el.circle',
  translateX: 250,
}, '-=600') // relative offset
.add({
  targets: '.offsets-demo .el.triangle',
  translateX: 250,
}, 400); // absolute offset
taenykim commented 2 years ago

keyframes

anime({
  targets: '.property-keyframes-demo .el',
  translateX: [
    { value: 250, duration: 1000, delay: 500 },
    { value: 0, duration: 1000, delay: 500 }
  ],
  translateY: [
    { value: -40, duration: 500 },
    { value: 40, duration: 500, delay: 1000 },
    { value: 0, duration: 500, delay: 1000 }
  ],
  scaleX: [
    { value: 4, duration: 100, delay: 500, easing: 'easeOutExpo' },
    { value: 1, duration: 900 },
    { value: 4, duration: 100, delay: 500, easing: 'easeOutExpo' },
    { value: 1, duration: 900 }
  ],
  scaleY: [
    { value: [1.75, 1], duration: 500 },
    { value: 2, duration: 50, delay: 1000, easing: 'easeOutExpo' },
    { value: 1, duration: 450 },
    { value: 1.75, duration: 50, delay: 1000, easing: 'easeOutExpo' },
    { value: 1, duration: 450 }
  ],
  easing: 'easeOutElastic(1, .8)',
  loop: true
});
taenykim commented 2 years ago

stagger

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-05-22 แ„‹แ…ฉแ„’แ…ฎ 7 05 54

easing

anime({
  targets: ".staggering-easing-demo .el",
  translateX: 270,
  delay: anime.stagger(1000, { easing: "easeOutQuad" }),
});

gird

anime({
  targets: ".staggering-grid-demo .el",
  scale: [
    { value: 2, easing: "easeInOutQuad", duration: 200 },
    { value: 1, easing: "easeInOutQuad", duration: 300 },
  ],
  delay: anime.stagger(200, { grid: [14, 5], from: "center" }),
});

axes

anime({
  targets: ".staggering-axis-grid-demo .el",
  translateX: anime.stagger(10, { grid: [14, 5], from: "first", axis: "x" }),
  translateY: anime.stagger(10, { grid: [14, 5], from: "first", axis: "y" }),
  rotateZ: anime.stagger([0, 90], { grid: [14, 5], from: "first", axis: "x" }),
  delay: anime.stagger(100, { grid: [14, 5], from: "first" }),
  easing: "easeInOutQuad",
  duration: 700,
});
taenykim commented 2 years ago

๐Ÿ•น play, pause, restart, reverse (Method)

const animation = anime({
   ...
   autoplay: false
});

animation.play();
animation.pause();
animation.restart();
animation.reverse();

animation.seek(timeStamp); /* timeStamp๋กœ ์‹œ๊ฐ„์ด๋™. animation.duration * percent */
taenykim commented 2 years ago

Update

taenykim commented 2 years ago

Promise

const ani = anime({})
ani.finished.then(() => {
  console.log("hey");
});