-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
437 lines (273 loc) · 14 KB
/
index.html
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>[CSS3] 認識CSS3 transitions - apa</title>
<meta name="author" content="阿帕">
<meta name="description" content="一直沒有找個時間好好的了解一下CSS3 transitions,趁著看到這篇文章,就來筆記一下用法,扎實一下基本功 CSS3 transitions可以改變css屬性的值,在某個期間內做出變化,類似jQuery.animate(),語法結構如下 .example { transition- …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://blog.rx836.tw/blog/css3-transitions-guide/">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="/atom.xml" rel="alternate" title="apa" type="application/atom+xml">
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<meta property="fb:admins" content="100000102681259"/>
<meta property="fb:app_id" content="416172151763823" />
<meta property="og:title" content="[CSS3] 認識CSS3 transitions - apa" />
<meta property="og:description" content="一直沒有找個時間好好的了解一下CSS3 transitions,趁著看到這篇文章,就來筆記一下用法,扎實一下基本功 CSS3 transitions可以改變css屬性的值,在某個期間內做出變化,類似jQuery.animate(),語法結構如下 .example { transition- …" />
<meta property="og:url" content="http://blog.rx836.tw/blog/css3-transitions-guide/" />
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-31245620-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">apa</a></h1>
<h2>Stay Hungry, Stay Foolish</h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:blog.rx836.tw" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">[CSS3] 認識CSS3 Transitions</h1>
<p class="meta">
<time datetime="2012-10-20T23:24:00+08:00" pubdate data-updated="true">Oct 20<span>th</span>, 2012</time>
| <a href="#disqus_thread">Comments</a>
</p>
</header>
<div class="entry-content"><p>一直沒有找個時間好好的了解一下CSS3 transitions,趁著看到<a href="http://www.adobe.com/devnet/html5/articles/using-css3-transitions-a-comprehensive-guide.html" target="_blank">這篇</a>文章,就來筆記一下用法,扎實一下基本功</p>
<!--more-->
<p>CSS3 transitions可以改變css屬性的值,在某個期間內做出變化,類似<a href="http://api.jquery.com/animate/" target="_blank">jQuery.animate()</a>,語法結構如下</p>
<pre><code>.example {
transition-property: background-color;
transition-duration: 2s;
transition-timing-function: ease-in;
transition-delay: 1s;
}
</code></pre>
<p>這裡沒有特別加上prefixes,在真正使用的時候要自行加上,接著是分別講解每個屬性的用途</p>
<p><strong>transition-property:</strong> 指定你要變化的CSS屬性,至於哪些屬性是擁有transition效果可以查看<a href="http://www.w3.org/TR/css3-transitions/#animatable-properties" target="_blank">這張表</a></p>
<p><strong>transition-duration:</strong> 指定transition從開始到結束的變化時間,在數字後面加上s就是以秒計算,用ms就是微秒</p>
<p><strong>transition-timing-function:</strong> 根據時間的進行去改變屬性值的變化速率,也就是貝茲曲線,詳細的介紹可以參考<a href="http://www.w3.org/TR/css3-transitions/#transition-timing-function-property" target="_blank">這篇</a>,基本的有linear, ease-in, ease-out和ease-in-out這些值可以使用</p>
<p><strong>transition-delay:</strong> 可以指定秒或微秒來延遲transition觸發的時間</p>
<h3>Transition shorthand</h3>
<p>為了簡潔也可以這樣寫</p>
<pre><code>.example {
transition: background-color 2s ease-in 1s;
}
</code></pre>
<p>要特別注意的是,順序的重要性,另外第一個時間代表是<strong>transition-duration</strong>,第二個時間是<strong>transition-delay</strong>,如果你要定義<strong>transition-delay</strong>一定要先定義<strong>transition-duration</strong>才行</p>
<h3>Multiple transitions</h3>
<p>如果想在同個元素上定義複數個transitions,可以用下面寫法</p>
<pre><code>.example {
transition: background-color 2s ease-in 1s,
width 2s ease-in-out,
height 3s ease-out;
}
</code></pre>
<p>記得要用<strong>逗號</strong>隔開</p>
<h3>Triggering a transition</h3>
<p>但其實光寫上面那些語法並不能實現transitions,原因在於沒有<strong>觸發</strong>這個動作,所以我們可能要加些”動作”,例如比較常見的是<strong>:hover</strong></p>
<pre><code>.example {
background-color: green;
transition: background-color 2s ease-in 1s;
width:100px;
height:100px;
}
.example:hover {
background-color: blue
}
</code></pre>
<p><a href="http://jsfiddle.net/Pa5Uk/1/" target="_blank">範例</a></p>
<p>會看到如果將滑鼠移到div .example上面,會先等待一秒,接著再花兩秒的時間從綠色轉換成藍色</p>
<h3>Transitions triggered by JavaScript</h3>
<p>假如要搭配JavaScript呢?我們可以使用jQuery來示範一下</p>
<p>css</p>
<pre><code>.example {
background-color: green;
transition: background-color 2s ease-in 1s;
width:100px;
height:100px;
}
.style-change {
background-color: blue
}
</code></pre>
<p>html</p>
<pre><code><div id="a" class="example"></div>
</code></pre>
<p>js</p>
<pre><code>$("#a").click(function() {
$(".example").toggleClass("style-change");
});
</code></pre>
<p><a href="http://jsfiddle.net/Rnebd/" target="_blank">範例</a></p>
<p>這樣就可以搭配著js來使用transition的效果</p>
<h3>Transition tricks and techniques</h3>
<p>有了前面的一些基本用法以外,接下來介紹的是一些小技巧,前面的<strong>:hover</strong>例子不管是從綠色切換成藍色,還是藍色切換回綠色,都是同樣的效果和速度,但其實可以針對這兩者去做變化,例如</p>
<pre><code>.example {
background-color: green;
transition: background-color 1s ease-out;
width:100px;
height:100px;
}
.example:hover {
background-color: blue;
transition: background-color 5s linear;
}
</code></pre>
<p>這段意思是從綠色到藍色要花一秒的時間,但從藍色變回綠色要花五秒,就可以做出比較不一樣的效果</p>
<pre><code>.example {
width: 100px;
height: 100px;
background-color: blue;
transition: width 0s ease-out 999999s,
height 0s ease-out 999999s; }
.example:active {
width: 200px;
height: 200px;
transition: width 2s,
height 2s;
}
</code></pre>
<p>當然也可以把transition-delay設為999999s,這樣就可以將效果一直保存</p>
<p>只是我目前還不知道這樣的保存可以用來做啥就是了…</p>
<p>參考資料:</p>
<p><a href="http://www.adobe.com/devnet/html5/articles/using-css3-transitions-a-comprehensive-guide.html" target="_blank">Using CSS3 transitions: A comprehensive guide</a></p>
<p><a href="http://www.w3cplus.com/content/css3-transition" target="_blank">CSS3 Transition</a></p>
<p>內容如有錯誤,歡迎指正</p>
</div>
<div>如果你覺得這篇文章有幫助,請幫我讚聲一下:)</div>
<div class="sharing">
<div class="fb-like" data-send="true" data-width="450" data-show-faces="false"></div>
</div>
<footer>
<p class="meta">
<span class="byline author vcard">Posted by <span class="fn">阿帕</span></span>
<time datetime="2012-10-20T23:24:00+08:00" pubdate data-updated="true">Oct 20<span>th</span>, 2012</time>
<span class="categories">
<a class='category' href='/blog/categories/css/'>CSS</a>
</span>
</p>
<p class="meta">
<a class="basic-alignment left" href="/blog/javascript-currying/" title="Previous Post: [JavaScript] 如何保留重複參數的函式,不必每次傳遞-Currying">« [JavaScript] 如何保留重複參數的函式,不必每次傳遞-Currying</a>
<a class="basic-alignment right" href="/blog/windows8-notifications/" title="Next Post: [Win8] 動態磚初體驗">[Win8] 動態磚初體驗 »</a>
</p>
</footer>
</article>
<section>
<h1>Comments</h1>
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>
<section>
<h1>FB Comments</h1>
<div id="facebook_comments" aria-live="polite">
<noscript>Please enable JavaScript to view the comments powered by facebook</noscript>
<div class="fb-comments"
data-href="http://blog.rx836.tw/blog/css3-transitions-guide/"
data-num-posts="5"
data-width="570">
</div>
</div>
</section>
</div>
<aside class="sidebar">
<section>
<h1>Categories</h1>
<ul id="category-list"><li><a href='/blog/categories/css'>CSS (14)</a></li><li><a href='/blog/categories/facebook'>Facebook (5)</a></li><li><a href='/blog/categories/html5'>HTML5 (2)</a></li><li><a href='/blog/categories/javascript'>JavaScript (7)</a></li><li><a href='/blog/categories/jq-plugin'>jQ-Plugin (11)</a></li><li><a href='/blog/categories/jquery'>jQuery (19)</a></li><li><a href='/blog/categories/octopress'>Octopress (3)</a></li><li><a href='/blog/categories/phonegap'>PhoneGap (3)</a></li><li><a href='/blog/categories/win8'>Win8 (4)</a></li><li><a href='/blog/categories/好書分享'>好書分享 (6)</a></li><li><a href='/blog/categories/學習筆記'>學習筆記 (8)</a></li></ul>
</section>
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/blog/css-styling-scrollbars/">[CSS] 用CSS改變scrollbar</a>
</li>
<li class="post">
<a href="/blog/css-cursor-rule/">[CSS] 關於CSS Cursor</a>
</li>
<li class="post">
<a href="/blog/css-positioning/">[CSS] CSS position 觀念筆記心得</a>
</li>
<li class="post">
<a href="/blog/jquery-tags-manager/">[jQ-Plugin] 輕鬆加入Tag標籤功能的plugin-Tags Manager</a>
</li>
<li class="post">
<a href="/blog/javascript-documentframent/">[JavaScript] DocumentFragments-JS加快效能的好物</a>
</li>
</ul>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2013 - 阿帕 -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript">
var disqus_shortname = 'rx836';
// var disqus_developer = 1;
//var disqus_identifier = 'http://blog.rx836.tw/blog/css3-transitions-guide/';
var disqus_identifier = 'http://blog.rx836.tw/blog/css3-transitions-guide/';
var disqus_url = 'http://blog.rx836.tw/blog/css3-transitions-guide/';
var disqus_script = 'embed.js';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=416172151763823";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>