aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/css/transform-function/translate3d/index.html
blob: 02a45a318643cc925fc76c689003b9e551329b1c (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: translate3d()
slug: Web/CSS/transform-function/translate3d
translation_of: Web/CSS/transform-function/translate3d()
original_slug: Web/CSS/transform-function/translate3d()
---
<div>{{CSSRef}}</div>

<p><strong><code>translate3d()</code></strong> <a href="/zh-TW/docs/Web/CSS">CSS</a> 函式以 3D 場境的方式定位元素。其結果為 {{cssxref("&lt;transform-function&gt;")}} 資料型別。</p>

<div>{{EmbedInteractiveExample("pages/css/function-translate3d.html")}}</div>



<p>這個轉場的特徵是三維向量,其坐標則定義元素的方向該如何移動。</p>

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

<pre class="syntaxbox notranslate">translate3d(tx, ty, tz)
</pre>

<h3 id="數值">數值</h3>

<dl>
 <dt><code>tx</code></dt>
 <dd>{{cssxref("&lt;length&gt;")}} 代表平移向量的橫坐標。</dd>
 <dt><code>ty</code></dt>
 <dd>{{cssxref("&lt;length&gt;")}} 代表平移向量的縱坐標。</dd>
 <dt><code>tz</code></dt>
 <dd>{{cssxref("&lt;length&gt;")}} 代表平移向量的 z 分量。數值不能是 {{cssxref("&lt;percentage&gt;")}}:否則,此轉場的屬性無效。</dd>
</dl>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col"><sup>2</sup> 上的笛卡兒座標(Cartesian coordinate)</th>
   <th scope="col">ℝℙ<sup>2</sup> 上的齊次坐標(homogeneous coordinates)</th>
   <th scope="col"><sup>3</sup> 上的笛卡兒座標</th>
   <th scope="col">ℝℙ<sup>3</sup> 上的齊次坐標</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td colspan="2" rowspan="2">
    <p>This transformation applies to the 3D space and can't be represented on the plane.</p>
   </td>
   <td colspan="1" rowspan="2">A translation is not a linear transformation in ℝ<sup>3</sup> and can't be represented using a Cartesian-coordinate matrix.</td>
   <td colspan="1" rowspan="2"><math> <mfenced><mtable><mtr>1<mtd>0</mtd><mtd>0</mtd><mtd>tx</mtd></mtr><mtr>0<mtd>1</mtd><mtd>0</mtd><mtd>ty</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd><mtd>tz</mtd></mtr><mtr><mtd>0</mtd><mtd>0</mtd><mtd>0</mtd><mtd>1</mtd></mtr></mtable> </mfenced> </math></td>
  </tr>
 </tbody>
</table>

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

<h3 id="使用單軸平移">使用單軸平移</h3>

<h4 id="HTML">HTML</h4>

<pre class="brush: html notranslate">&lt;div&gt;Static&lt;/div&gt;
&lt;div class="moved"&gt;Moved&lt;/div&gt;
&lt;div&gt;Static&lt;/div&gt;</pre>

<h4 id="CSS">CSS</h4>

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

.moved {
  /* Equivalent to perspective(500px) translateX(10px) */
  transform: perspective(500px) translate3d(10px, 0, 0px);
  background-color: pink;
}
</pre>

<h4 id="結果">結果</h4>

<p>{{EmbedLiveSample("Using_a_single_axis_translation", 250, 250)}}</p>

<h3 id="Combining_z-axis_and_x-axis_translation">Combining z-axis and x-axis translation</h3>

<h4 id="HTML_2">HTML</h4>

<pre class="brush: html notranslate">&lt;div&gt;Static&lt;/div&gt;
&lt;div class="moved"&gt;Moved&lt;/div&gt;
&lt;div&gt;Static&lt;/div&gt;</pre>

<h4 id="CSS_2">CSS</h4>

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

.moved {
  transform: perspective(500px) translate3d(10px, 0, 100px);
  background-color: pink;
}
</pre>

<h4 id="結果_2">結果</h4>

<p>{{EmbedLiveSample("Combining_z-axis_and_x-axis_translation", 250, 250)}}</p>

<h2 id="瀏覽器相容性">瀏覽器相容性</h2>

<p>請參見 <code><a href="/zh-TW/docs/Web/CSS/transform-function#Browser_compatibility">&lt;transform-function&gt;</a></code></p>

<h2 id="參見">參見</h2>

<ul>
 <li>{{cssxref("transform")}}</li>
 <li>{{cssxref("&lt;transform-function&gt;")}}</li>
</ul>