[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API [Back]  [Original]

API - Web API | MDN

MDN Web Docs

View in English Always switch to English

API

API JavaScript

API

API JavaScript API CSS CSS Window.requestAnimationFrame() 1

API JavaScript CSS DOM CSS JavaScript API

APIRachel Nabors CodePen

API CSS

API CSS CSS

CSS

CSS

"Play" CSS

css
#alice {
  animation: alice-tumbling infinite 3s linear;
}

@keyframes alice-tumbling {
  0% {
    color: black;
    transform: rotate(0) translate3d(-50%, -50%, 0);
  }
  30% {
    color: #431236;
  }
  100% {
    color: black;
    transform: rotate(360deg) translate3d(-50%, -50%, 0);
  }
}

3 @keyframes 30% 0.9

JavaScript

API

Keyframe CSS @keyframes

js
const aliceTumbling = [
  { transform: "rotate(0) translate3d(-50%, -50%, 0)", color: "black" },
  { color: "#431236", offset: 0.3 },
  { transform: "rotate(360deg) translate3d(-50%, -50%, 0)", color: "black" },
];

CSS CSS API 3 Keyframe 50%

CSS 30%50% offset: 0.3

2 2 1 Element.animate() NotSupportedError DOMException

js
const aliceTiming = {
  duration: 3000,
  iterations: Infinity,
};

CSS

: CSS "infinite" JavaScript Infinity timing-function easing easing animation-timing-function ease CSS API linear

Element.animate() 2

js
document.getElementById("alice").animate(aliceTumbling, aliceTiming);

animate() CSS DOM

js
document.getElementById("alice").animate(
  [
    { transform: "rotate(0) translate3d(-50%, -50%, 0)", color: "black" },
    { color: "#431236", offset: 0.3 },
    { transform: "rotate(360deg) translate3d(-50%, -50%, 0)", color: "black" },
  ],
  {
    duration: 3000,
    iterations: Infinity,
  },
);

1

js
document.getElementById("alice").animate(
  [
    { transform: "rotate(0) translate3d(-50%, -50%, 0)", color: "black" },
    { color: "#431236", offset: 0.3 },
    { transform: "rotate(360deg) translate3d(-50%, -50%, 0)", color: "black" },
  ],
  3000,
);

play(), pause(), reverse(), updatePlaybackRate()

API CSS API API Follow the White Rabbit

animate()

js

Element.animate() Animation.pause()

js

: Animation() rabbitDownAnimation play()

Animation.play()

js

downHeGoes

playbackRate playbackRate Through the Looking-Glass

playbackRate updatePlaybackRate() playbackRate

js
setInterval(() => {
  //  0.4 
  if (redQueenAlice.playbackRate > 0.4) {
    redQueenAlice.updatePlaybackRate(redQueenAlice.playbackRate * 0.9);
  }
  adjustBackgroundPlayback();
}, 1000);

playbackRate

js
function goFaster() {
  // 
  redQueenAlice.updatePlaybackRate(redQueenAlice.playbackRate * 1.1);
  adjustBackgroundPlayback();
}

document.addEventListener("click", goFaster);
document.addEventListener("touchstart", goFaster);

playbackRate 2

js
/*  
  
*/
const sceneries = [
  foreground1Movement,
  foreground2Movement,
  background1Movement,
  background2Movement,
];

function adjustBackgroundPlayback() {
  //  0.8  1.2 
  // 
  // 0.8 
  if (redQueenAlice.playbackRate < 0.8) {
    sceneries.forEach((anim) => {
      anim.updatePlaybackRate(-redQueenAlice.playbackRate / 2);
    });
  } else if (redQueenAlice.playbackRate > 1.2) {
    sceneries.forEach((anim) => {
      anim.updatePlaybackRate(redQueenAlice.playbackRate / 2);
    });
  } else {
    sceneries.forEach((anim) => {
      anim.updatePlaybackRate(0);
    });
  }
}
adjustBackgroundPlayback();

fill forwards 2 fill

Animation.commitStyles() style

4 JavaScript

remove

persist()

replaceState removed persist() persisted active

playbackRate CSS CSS API Document.getAnimations playbackRate

js
document.getAnimations().forEach((animation) => {
  animation.updatePlaybackRate(animation.playbackRate * 0.5);
});

API 1

CSS /

js
document.getElementById("eat-me-sprite").animate([], {
  duration: aliceChange.effect.getComputedTiming().duration / 2,
});

js
const aliceChange = document
  .getElementById("alice")
  .animate(
    [
      { transform: "translate(-50%, -50%) scale(.5)" },
      { transform: "translate(-50%, -50%) scale(2)" },
    ],
    {
      duration: 8000,
      easing: "ease-in-out",
      fill: "both",
    },
  );

8 2

js
aliceChange.pause();

"playhead" Animation.currentTime 4

js
aliceChange.currentTime = 4000;

currentTime 2 aliceChange Animation.effect

js
aliceChange.currentTime = aliceChange.effect.getComputedTiming().duration / 2;

effect aliceChange.effect.getComputedTiming() duration

js
const drinking = document
  .getElementById("liquid")
  .animate([{ height: "100%" }, { height: "0" }], {
    fill: "forwards",
    duration: aliceChange.effect.getComputedTiming().duration / 2,
  });
drinking.pause();

3 1 1

API currentTime activeDuration

js
const endGame = () => {
  // 
  const alicePlayhead = aliceChange.currentTime;
  const aliceTimeline = aliceChange.effect.getComputedTiming().activeDuration;

  // 
  stopPlayingAlice();

  // 3 
  const aliceHeight = alicePlayhead / aliceTimeline;

  if (aliceHeight <= 0.333) {
    // 
    // 
  } else if (aliceHeight >= 0.666) {
    // 
    // 
  } else {
    // 
    // 
  }
};

CSS API

endGame

js
// 
nommingCake.onfinish = endGame;
drinking.onfinish = endGame;

// 
aliceChange.onfinish = endGame;

API finished

API


Web Proxy Viewer  |  New URL  |  Original Page