KeyframeEffect: target-Eigenschaft

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2020.

Die target-Eigenschaft des KeyframeEffect-Interfaces repräsentiert das Element oder Pseudo-Element, das animiert wird. Sie kann null sein für Animationen, die kein spezifisches Element anvisieren. Sie fungiert sowohl als Getter als auch als Setter, außer bei Animationen und Übergängen, die durch CSS generiert werden.

Wert

Ein Element oder null.

Beispiele

Im folgenden Beispiel wurde emoji als target-Element gesetzt, das animiert werden soll:

js
const emoji = document.querySelector("div"); // element to animate

const rollingKeyframes = new KeyframeEffect(
  emoji,
  [
    { transform: "translateX(0) rotate(0)" }, // keyframe
    { transform: "translateX(200px) rotate(1.3turn)" }, // keyframe
  ],
  {
    // keyframe options
    duration: 2000,
    direction: "alternate",
    easing: "ease-in-out",
    iterations: "Infinity",
  },
);

const rollingAnimation = new Animation(rollingKeyframes, document.timeline);
rollingAnimation.play();

// logs "<div>🤣</div>"
console.log(rollingKeyframes.target);
html
<div>🤣</div>

Spezifikationen

Specification
Web Animations
# dom-keyframeeffect-target

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
target

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch