-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimations.php
More file actions
120 lines (116 loc) · 3.51 KB
/
animations.php
File metadata and controls
120 lines (116 loc) · 3.51 KB
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
<section id="how2animations">
<h1>How to use animations</h1>
<p class="note">As of May 2010, this only works in Webkit browsers.</p>
<p>CSS animations were introduced into Webkit in 2007, though at the time of writing there was no support in any other browsers. Firefox has a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=435442">bug filed</a> relating to the implementation, but it isn't assigned to anyone.</p>
<p>In 2009 a <a href="http://www.w3.org/TR/css3-animations/">working draft</a> was written and added to the w3c site.</p>
<p>To use CSS animation, you first specify some keyframes for the animation - basically what styles will the element have at certain times. The browser does the tweening for you.</p>
<h2>Demo</h2>
<style>
@-webkit-keyframes resize {
0% {
padding: 0;
}
50% {
padding: 0 20px;
background-color:rgba(255,0,0,0.2);
}
100% {
padding: 0 100px;
background-color:rgba(255,0,0,0.9);
}
}
#animationDemo {
height:100px;
width:500px;
margin:0 auto;
}
#animationDemo #box {
height:50px;
width:50px;
margin:0 auto;
border:1px red solid;
background-color:rgba(255,0,0,0.7);
}
#animationDemo:hover #box, #animationDemo.hover_effect #box {
-webkit-animation-name: resize;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: 4;
-webkit-animation-direction: alternate;
}
</style>
<div id="animationDemo" class="hover">
<div id="box" class="shadow"></div>
<p class="center">Hover over me</p>
</div>
<h2>Code</h2>
<p>The interesting bit of this code is this bit of CSS:</p>
<pre class="css">
@-webkit-keyframes resize {
0% {
padding: 0;
}
50% {
padding: 0 20px;
background-color:rgba(255,0,0,0.2);
}
100% {
padding: 0 100px;
background-color:rgba(255,0,0,0.9);
}
}
#box {
-webkit-animation-name: resize;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: 4;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease-in-out;
}
</pre>
<p>Note that the 4 iterations makes the box pulse twice - the animation runs forwards then backwards, then forwards then backwards.</p>
<p>You can have as many keyframes as you like, at whatever intervals you like.</p>
<p>A useful setting is to set <code>animation-iteration-count</code> to <code>infinite</code>, making the animation continue for ever.</p>
<h2>Demo</h2>
<style>
@-webkit-keyframes glow {
0% {
-webkit-box-shadow: 0 0 16px rgba(66, 140, 240, 0.5);
border-color: rgba(0,0,255,0.5);
}
100% {
-webkit-box-shadow: 0 0 16px rgba(66, 140, 240, 1.0), 0 0 36px rgba(0, 140, 255, 1.0);
border-color: rgba(0,0,255,1.0);
}
}
#animationDemo2 {
width:255px;
margin:10px auto;
}
#animationDemo2 button {
width: 255px;
height: 35px;
background: #cde;
border: 2px solid #ccc;
border-color: rgba(0,0,255,0.5);
font-size:18px;
color: #000;
text-shadow: rgba(20, 20, 20, 0.5) 1px 1px 5px;
text-align: center;
-webkit-border-radius: 16px;
-moz-border-radius: 16px;
border-radius: 16px;
-webkit-box-shadow: 0 0 16px rgba(66, 140, 240, 0.5);
}
#animationDemo2 button:hover, #animationDemo2 button.hover_effect {
background-color:#cce;
-webkit-animation-name: glow;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-timing-function: ease-in-out;
}
</style>
<div id="animationDemo2">
<button class="transition hover">Hover to Pulsate</button>
</div>
<p>The key to using these animations is subtlety - nice delicate animations, rather than extreme over the top ones!</p>
</section>