-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathflip.php
269 lines (258 loc) · 7.91 KB
/
flip.php
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
<section id="flip">
<h1>Flipping content</h1>
<h2>Demo 1 - Flipping a simple image to a div (transitions and 3d transforms)</h2>
<p class="note">As of January 2012, this works in Safari (inc. iOS), Chrome, Firefox 10 and IE10.</p>
<h3>Plan</h3>
<ol>
<li>Put an image on top of a div inside a container.</li>
<li>Put that in another container with perspective defined.</li>
<li>When hovering on the outside container, add a rotate around the Y axis to the inside container.</li>
</ol>
<h3>Demo</h3>
<style>
#f1_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
.face.back {
display: none;
}
#f1_container {
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-o-perspective: 1000px;
-ms-perspective: 1000px;
perspective: 1000px;
}
#f1_card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
-moz-transform-style: preserve-3d;
-moz-transition: all 1.0s linear;
-o-transform-style: preserve-3d;
-o-transition: all 1.0s linear;
-ms-transform-style: preserve-3d;
-ms-transition: all 1.0s linear;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f1_container:hover #f1_card, #f1_container.hover_effect #f1_card {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
transform: rotateY(180deg);
-webkit-box-shadow: -5px 5px 5px #aaa;
-moz-box-shadow: -5px 5px 5px #aaa;
box-shadow: -5px 5px 5px #aaa;
}
.face {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
}
.face.back {
display: block;
-webkit-transform: rotateY(180deg);
-webkit-box-sizing: border-box;
-moz-transform: rotateY(180deg);
-moz-box-sizing: border-box;
-o-transform: rotateY(180deg);
-o-box-sizing: border-box;
-ms-transform: rotateY(180deg);
-ms-box-sizing: border-box;
transform: rotateY(180deg);
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
}
</style>
<div id="f1_container" class="hover">
<div id="f1_card" class="shadow">
<div class="front face">
<img src="/images/Stones.jpg"/>
</div>
<div class="back face center">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
<h3>Code</h3>
<p>First, the markup.</p>
<pre class="prettyprint lang-html">
<div id="f1_container">
<div id="f1_card" class="shadow">
<div class="front face">
<img src="/images/Stones.jpg"/>
</div>
<div class="back face center">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
</pre>
<p>Then the CSS, stripped of the vendor prefixes to keep it clean.</p>
<pre class="prettyprint lang-css">
#f1_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
.face.back {
display: none;
}
#f1_container {
perspective: 1000;
}
#f1_card {
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f1_container:hover #f1_card {
transform: rotateY(180deg);
box-shadow: -5px 5px 5px #aaa;
}
.face {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.face.back {
display: block;
transform: rotateY(180deg);
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
}
</pre>
<p>You can also flip around the X and Z axes:</p>
<style>
#f2_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
#f2_container {
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-o-perspective: 1000px;
-ms-perspective: 1000px;
perspective: 1000px;
}
#f2_card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
-moz-transform-style: preserve-3d;
-moz-transition: all 1.0s linear;
-o-transform-style: preserve-3d;
-o-transition: all 1.0s linear;
-ms-transform-style: preserve-3d;
-ms-transition: all 1.0s linear;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f2_container:hover #f2_card, #f2_container.hover_effect #f2_card {
-webkit-transform: rotateX(180deg);
-moz-transform: rotateX(180deg);
-o-transform: rotateX(180deg);
-ms-transform: rotateX(180deg);
transform: rotateX(180deg);
-webkit-box-shadow: 5px -5px 5px #aaa;
-moz-box-shadow: 5px -5px 5px #aaa;
box-shadow: 5px -5px 5px #aaa;
}
</style>
<div id="f2_container" class="hover">
<div id="f2_card" class="shadow">
<div class="front face">
<img src="/images/Cirques.jpg"/>
</div>
<div class="back face center">
<p>Note that I've had to change the shadow to keep it looking normal.</p>
</div>
</div>
</div>
<style>
#f3_container {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
#f3_container {
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-o-perspective: 1000px;
-ms-perspective: 1000px;
perspective: 1000px;
}
#f3_card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
-moz-transform-style: preserve-3d;
-moz-transition: all 1.0s linear;
-o-transform-style: preserve-3d;
-o-transition: all 1.0s linear;
-ms-transform-style: preserve-3d;
-ms-transition: all 1.0s linear;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
#f3_container:hover #f3_card, #f3_container.hover_effect #f3_card {
-webkit-transform: rotateZ(180deg);
-moz-transform: rotateZ(180deg);
-o-transform: rotateZ(180deg);
-ms-transform: rotateZ(180deg);
-webkit-box-shadow: -5px -5px 5px #aaa;
-moz-box-shadow: -5px -5px 5px #aaa;
box-shadow: -5px -5px 5px #aaa;
}
</style>
<div id="f3_container" class="hover">
<div id="f3_card" class="shadow">
<div class="front face">
<img src="/images/Stones.jpg"/>
</div>
<div class="back face center">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
<h2>Case Study: Flipping cards on the <a href="http://www.southamptontaxis.org/our-partners/">Southampton Hackney Association's Website</a></h2>
<p>Part of the design for the Southampton Hackney Association included a grid of sponsors. The design was such that on hover or click, they would flip over revealing a contact number, email address or URL. We wanted this site to work on browsers that didn't support 3D transforms, as at the time, only webkit had support.</p>
<h3>Code path for browsers with 3D transforms</h3>
<p>The code used is exactly as above. The markup consists of a div, containing two divs for the back and front faces.</p>
<h3>Fallback</h3>
<p>In older browsers, <a href="http://lab.smashup.it/flip">jQuery Flip</a> is used. <a href="http://www.modernizr.com/">Modernizr</a> is used to detect support for 3D transforms and if not, the markup is altered to fit how jQuery flip requires it to be. The key part is that for normal browsers, normal 3D transforms are used, with none of the fluff required to get this to work.</p>
<p>Due to issues with getting jQuery flip to work on hover, the behaviour was changed to work on click.</p>
<p>Using this technique, the effect works on all browsers in use, back to IE6. The flip effect is of much higher quality on browsers that support 3D transforms, but still has the distinctive look and feel on older browsers. As we move forward, the percentage of users who hit the fallback will decrease.</p>
</section>