aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/transform-function/matrix()/index.html
blob: 61a7db51241afa6221f1e35a8a3ff7a120c2c2f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
title: matrix()
slug: Web/CSS/transform-function/matrix()
translation_of: Web/CSS/transform-function/matrix()
---
<p>CSS函数 <code>matrix()</code> 指定了一个由指定的 6 个值组成的 2D 变换矩阵。这种矩阵的常量值是隐含的,而不是由参数传递的;其他的参数是以列优先的顺序描述的。</p>

<p><code>matrix(a, b, c, d, tx, ty)</code><code>matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1)</code> 的简写。</p>

<div class="note"><strong>注意:</strong> 直到 Firefox 16, Gecko 才接受对于 <strong>tx</strong><strong> ty </strong>{{cssxref("&lt;length&gt;")}} 值.</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox notranslate">matrix(<em>a</em>, <em>b</em>, <em>c</em>, <em>d</em>, <em>tx</em>, <em>ty</em>)
</pre>

<h2 id="参数值">参数值</h2>

<dl>
 <dt><em>a</em> <em>b</em> <em>c</em> <em>d</em></dt>
 <dd>描述线性变换的 {{cssxref("&lt;number&gt;")}}</dd>
 <dt><em>tx</em> <em>ty</em></dt>
 <dd>描述如何应用这个变换的 {{cssxref("&lt;number&gt;")}}</dd>
</dl>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col"><sup>2 </sup>下的<a href="https://zh.wikipedia.org/wiki/%E7%AC%9B%E5%8D%A1%E5%B0%94%E5%9D%90%E6%A0%87%E7%B3%BB">笛卡尔坐标</a></th>
   <th scope="col">ℝℙ<sup></sup><a href="https://zh.wikipedia.org/wiki/%E9%BD%90%E6%AC%A1%E5%9D%90%E6%A0%87">齐次坐标</a></th>
   <th scope="col"><sup>3</sup>下的<a href="https://zh.wikipedia.org/wiki/%E7%AC%9B%E5%8D%A1%E5%B0%94%E5%9D%90%E6%A0%87%E7%B3%BB">笛卡尔坐标</a></th>
   <th scope="col">ℝℙ<sup>3</sup>下的<a href="https://zh.wikipedia.org/wiki/%E9%BD%90%E6%AC%A1%E5%9D%90%E6%A0%87">齐次坐标</a></th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td colspan="1" rowspan="2"><math> <mfenced> <mtable> <mtr><mtd>a</mtd><mtd>c</mtd></mtr> <mtr><mtd>b</mtd><mtd>d</mtd></mtr> </mtable> </mfenced> </math></td>
   <td>
    <p><math> <mfenced> <mtable> <mtr><mtd></mtd></mtr></mtable></mfenced></math><br>
     a  c  tx<br>
     b  d  ty<br>
     0  0  1</p>
   </td>
   <td colspan="1" rowspan="2"><math> <mfenced> <mtable> <mtr><mtd></mtd></mtr>a  c  tx</mtable></mfenced></math><br>
    b  d  ty<br>
    0  0  1<mtr><mtd></mtd></mtr>  </td>
   <td colspan="1" rowspan="2"><math> <mfenced> <mtable> <mtr><mtd>a</mtd><mtd>c</mtd><mtd>0</mtd><mtd>tx</mtd></mtr><mtr><mtd>b</mtd><mtd>d</mtd><mtd>0</mtd><mtd>ty</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd><mtd>0</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td>
  </tr>
  <tr>
   <td><code>[a b c d tx ty]</code></td>
  </tr>
 </tbody>
</table>

<p>这些值表示以下函数:</p>

<p>matrix( scaleX(), skewY(), skewX(), scaleY(), translateX(), translateY() )</p>

<h2 id="示例">示例</h2>

<h3 id="HTML">HTML</h3>

<pre class="notranslate">&lt;div&gt;Normal&lt;/div&gt;
&lt;div class="changed"&gt;Changed&lt;/div&gt;
</pre>

<h3 id="CSS">CSS</h3>

<pre class="notranslate">div {
  width: 80px;
  height: 80px;
  background-color: skyblue;
}

.changed {
  transform: matrix(1, 2, -1, 1, 80, 80);
  background-color: pink;
}

</pre>

<h3 id="结果">结果</h3>

<p>请看英文版案例 <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix#Result">https://wiki.developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix#Result</a></p>