Beispiel:JS-WAAPI-1.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0">
<title>WAAPI - 1</title>

<style>
#gear {
	fill: #ddd;
	stroke: #333;
	stroke-width: 1;
}
svg {
    display: block;
	width: 10em;
	margin: 1em 0 0 1em;
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function () {

const gear = document.querySelector("#gear");
const playBtn = document.querySelector("#play");
const pauseBtn = document.querySelector("#pause");

const animation = gear.animate(
  [
    { rotate: "0" },
    { rotate: "1turn" }
  ],
  {
    duration: 3500,
    iterations: Infinity
  }
);

playBtn.addEventListener("click", () => {
  animation.play();
});

pauseBtn.addEventListener("click", () => {
  animation.pause();
});

});
</script>

</head>

<body>

<h1>Animation mit Web Animations API (WAAPI)</h1>
<div>
  <button id="play">Los!</button>
  <button id="pause">Pause</button>
</div>

<svg viewBox="-60 -60 120 120">
<g id="gear" tabindex="1">
  <path class="gear" d="m 1.7,-50.9 h -3.5 l -2.3,5.3 -0.2,5.1 -5.8,1 -1.9,-4.8 -3.9,-4.2 -3.3,1.2 -0.3,5.7 1.6,4.9 -5.1,2.9 -3.4,-3.8 -5.1,-2.6 -2.7,2.2 1.6,5.5 3.2,4 -3.8,4.5 -4.5,-2.4 -5.7,-0.7 -1.7,3 3.4,4.6 4.3,2.7 -2,5.6 -5.1,-0.8 -5.5,1.3 -0.6,3.4 4.7,3.2 5,1.1 v 5.9 l -5,1.1 -4.8,3.2 0.6,3.4 5.5,1.3 5,-0.8 2,5.6 -4.3,2.7 -3.4,4.6 1.8,3 5.6,-0.7 4.6,-2.5 3.8,4.5 -3.2,4 -1.6,5.5 2.7,2.2 5.1,-2.6 3.4,-3.8 5.1,2.9 -1.6,4.9 0.3,5.7 3.3,1.2 3.9,-4.1 1.9,-4.8 5.8,1 0.2,5.1 2.3,5.2 h 3.5 l 2.3,-5.2 0.2,-5.1 5.8,-1 1.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