Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. SVG
  3. Référence
  4. Attributs
  5. transform

Cette page a été traduite à partir de l'anglais par la communauté.Vous pouvez contribuer en rejoignant la communauté francophone sur MDN Web Docs.

View in EnglishAlways switch to English

transform

Baseline Widely available

Cette fonctionnalité est bien établie et fonctionne sur de nombreux appareils et versions de navigateurs. Elle est disponible sur tous les navigateurs depuis septembre 2015.

L'attributtransform définit une liste de définitions de transformation qui sont appliquées à l'élément ainsi qu'à ses éléments fils.

Exemple

html,body,svg {  height: 100%;}
html
<svg  viewBox="-40 0 150 100"  xmlns="http://www.w3.org/2000/svg"  xmlns:xlink="http://www.w3.org/1999/xlink">  <g    fill="grey"    transform="rotate(-10 50 100)                translate(-36 45.5)                skewX(40)                scale(1 0.5)">    <path           d="M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z" />  </g>  <use xlink:href="#heart" fill="none" stroke="red" /></svg>

Note :Pour SVG2,transform est un attribut de présentation et peut donc être utilisé comme une propriété CSS. Attention toutefois aux différences de syntaxe entre la propriété CSS et cet attribut. Voir la documentation de la propriététransform pour la syntaxe .

En tant qu'attribut de présentation,transform peut être utilisé par n'importe quel élément (en SVG 1.1, seuls les 16 éléments suivants pouvaient l'utiliser :<a>,<circle>,<clipPath>,<defs>,<ellipse>,<foreignObject>,<g>,<image>,<line>,<path>,<polygon>,<polyline>,<rect>,<switch>,<text> et<use>).

Pour des raisons historiques liées à SVG 1.1,<linearGradient> et<radialGradient> prennent en charge l'attributgradientTransform et<pattern> permet d'utiliserpatternTransform. Ces deux attributs sont exactement synonymes de l'attributtransform.

Valeur<transform-list>
Valeur par défautnone
Peut être animéOui

Fonctions de transformation

Les fonctions de transformation suivantes peuvent être utilisées par l'attributtransform.

Attention :Selon la spécification, on devrait également pouvoit utiliser les fonctions CSStransform functions mais la compatibilité n'est pas assurée.

matrix()

La fonction de transformationmatrix(<a> <b> <c> <d> <e> <f>) permet d'appliquer une transformation géométrique décrite par 6 coefficients etmatrix(a,b,c,d,e,f) sera équivalent à la matrice de transformation mathématique :

(acebdf001)\begin{pmatrix} a & c & e \ b & d & f \ 0 & 0 & 1 \end{pmatrix}
Le calcul des coordonnées s'obtient de la façon suivante :
(xnewCoordSysynewCoordSys1)=(acebdf001)(xprevCoordSysyprevCoordSys1)=(axprevCoordSys+cyprevCoordSys+ebxprevCoordSys+dyprevCoordSys+f1) \begin{pmatrix} x*{\mathrm{newCoordSys}} \ y*{\mathrm{newCoordSys}} \ 1 \end{pmatrix} = \begin{pmatrix} a & c & e \ b & d & f \ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x*{\mathrm{prevCoordSys}} \ y*{\mathrm{prevCoordSys}} \ 1 \end{pmatrix} = \begin{pmatrix} a x*{\mathrm{prevCoordSys}} + c y*{\mathrm{prevCoordSys}} + e \ b x*{\mathrm{prevCoordSys}} + d y*{\mathrm{prevCoordSys}} + f \ 1 \end{pmatrix}

Exemples

html,body,svg {  height: 100%;}
html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">  <rect x="10" y="10" width="30" height="20" fill="green" />  <!--  Dans l'exemple suivant, on applique la matrice suivante:  [a c e]    [3 -1 30]  [b d f] => [1  3 40]  [0 0 1]    [0  0  1]  qui transforme le rectangle de cette façon:  top left corner: oldX=10 oldY=10  newX = a * oldX + c * oldY + e = 3 * 10 - 1 * 10 + 30 = 50  newY = b * oldX + d * oldY + f = 1 * 10 + 3 * 10 + 40 = 80  top right corner: oldX=40 oldY=10  newX = a * oldX + c * oldY + e = 3 * 40 - 1 * 10 + 30 = 140  newY = b * oldX + d * oldY + f = 1 * 40 + 3 * 10 + 40 = 110  bottom left corner: oldX=10 oldY=30  newX = a * oldX + c * oldY + e = 3 * 10 - 1 * 30 + 30 = 30  newY = b * oldX + d * oldY + f = 1 * 10 + 3 * 30 + 40 = 140  bottom right corner: oldX=40 oldY=30  newX = a * oldX + c * oldY + e = 3 * 40 - 1 * 30 + 30 = 120  newY = b * oldX + d * oldY + f = 1 * 40 + 3 * 30 + 40 = 170  -->  <rect    x="10"    y="10"    width="30"    height="20"    fill="red"    transform="matrix(3 1 -1 3 30 40)" /></svg>

translate()

La fonction de transformationtranslate(<x> [<y>]) permet de déplacer un objet dex sur l'axe horizontal et dey sur l'axe vertical (i.e.xnew = xold + <x>, ynew = yold + <y>). Siy n'est pas fourni, la valeur par défaut est 0.

Exemples

html,body,svg {  height: 100%;}
html
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">  <!-- Pas de translation -->  <rect x="5" y="5" width="40" height="40" fill="green" />  <!-- Translation horizontale -->  <rect    x="5"    y="5"    width="40"    height="40"    fill="blue"    transform="translate(50)" />  <!-- Translation verticale -->  <rect    x="5"    y="5"    width="40"    height="40"    fill="red"    transform="translate(0 50)" />  <!-- Translation horizontale et verticale -->  <rect    x="5"    y="5"    width="40"    height="40"    fill="yellow"    transform="translate(50,50)" /></svg>

scale()

La fonction de transformationscale(<x> [<y>]) définit une homothétie d'un facteurx en horizontal et d'un facteury en vertical. Si la valeury n'est pas fournie, on considère qu'elle est égale àx.

Exemples

html,body,svg {  height: 100%;}
html
<svg viewBox="-50 -50 100 100" xmlns="http://www.w3.org/2000/svg">  <!-- uniform scale -->  <circle cx="0" cy="0" r="10" fill="red" transform="scale(4)" />  <!-- vertical scale -->  <circle cx="0" cy="0" r="10" fill="yellow" transform="scale(1,4)" />  <!-- horizontal scale -->  <circle cx="0" cy="0" r="10" fill="pink" transform="scale(4,1)" />  <!-- No scale -->  <circle cx="0" cy="0" r="10" fill="black" /></svg>

rotate()

La fonction de transformationrotate(<a> [<x> <y>]) définit une rotation dea degrés autour d'un point de coordonnéesx ety. Si les paramètres optionnelsx ety ne sont pas fournis, la rotation est effectuée autour de l'origine dans le système de coordonnés actuel.

Exemples

html,body,svg {  height: 100%;}
html
<svg viewBox="-12 -2 34 14" xmlns="http://www.w3.org/2000/svg">  <rect x="0" y="0" width="10" height="10" />  <!-- rotation is done around the point 0,0 -->  <rect x="0" y="0" width="10" height="10" fill="red" transform="rotate(100)" />  <!-- rotation is done around the point 10,10 -->  <rect    x="0"    y="0"    width="10"    height="10"    fill="green"    transform="rotate(100,10,10)" /></svg>

skewX()

La fonction de transformationskewX(<a>) définit une distorsion horizontale dea degrés.

Exemples

html,body,svg {  height: 100%;}
html
<svg viewBox="-5 -5 10 10" xmlns="http://www.w3.org/2000/svg">  <rect x="-3" y="-3" width="6" height="6" />  <rect x="-3" y="-3" width="6" height="6" fill="red" transform="skewX(30)" /></svg>

skewY()

La fonction de transformationskewY(<a>) définit une distorsion verticale dea degrés.

Exemples

html,body,svg {  height: 100%;}
html
<svg viewBox="-5 -5 10 10" xmlns="http://www.w3.org/2000/svg">  <rect x="-3" y="-3" width="6" height="6" />  <rect x="-3" y="-3" width="6" height="6" fill="red" transform="skewY(30)" /></svg>

Spécifications

Specification
CSS Transforms Module Level 1
# svg-transform
Scalable Vector Graphics (SVG) 2
# TransformProperty

Help improve MDN

Learn how to contribute

Cette page a été modifiée le par lescontributeurs du MDN.


[8]ページ先頭

©2009-2026 Movatter.jp