|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Transparent Glass with Shadow</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Transparent Glass with Shadow</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style scoped> |
|
|
29 |
#custom-doc { width: 95%; min-width: 950px; } |
|
|
30 |
#pagetitle {background-image: url(../../assets/bg_hd.gif);} |
|
|
31 |
#mygraphiccontainer { |
|
|
32 |
top: 20px; |
|
|
33 |
left: 20px; |
|
|
34 |
position: relative; |
|
|
35 |
width: 680px; |
|
|
36 |
height:500px; |
|
|
37 |
} |
|
|
38 |
.example { |
|
|
39 |
background: url(../assets/graphics/img/curtain.png) no-repeat center; |
|
|
40 |
} |
|
|
41 |
</style> |
|
|
42 |
<div class="intro"> |
|
|
43 |
<p> |
|
|
44 |
In this advanced example, we'll create a glass of milk by layering transparent gradients. Since gradient opacity does not work in IE <= 8, there will be a noticeable degradation in those browsers. |
|
|
45 |
</p> |
|
|
46 |
</div> |
|
|
47 |
<div class="example"> |
|
|
48 |
<div id="mygraphiccontainer"></div> |
|
|
49 |
<script> |
|
|
50 |
YUI({filter:"raw"}).use('graphics', function (Y) |
|
|
51 |
{ |
|
|
52 |
var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}); |
|
|
53 |
var shadow = mygraphic.addShape({ |
|
|
54 |
type: "ellipse", |
|
|
55 |
stroke: { |
|
|
56 |
color: "#ddd", |
|
|
57 |
weight: 0 |
|
|
58 |
}, |
|
|
59 |
fill: { |
|
|
60 |
type: "radial", |
|
|
61 |
stops: [ |
|
|
62 |
{color: "#000", opacity: 0.7, offset: 0}, |
|
|
63 |
{color: "#000", opacity: 0.4, offset: 0.5}, |
|
|
64 |
{color: "#000", opacity: 0.1, offset: 0.7} |
|
|
65 |
], |
|
|
66 |
cx: .6, |
|
|
67 |
cy: .6, |
|
|
68 |
fx: 0.1, |
|
|
69 |
fy: 0.3, |
|
|
70 |
r: 0.8 |
|
|
71 |
}, |
|
|
72 |
width: 280, |
|
|
73 |
height: 20, |
|
|
74 |
x:318, |
|
|
75 |
y:420 |
|
|
76 |
}); |
|
|
77 |
|
|
|
78 |
var milk = mygraphic.addShape({ |
|
|
79 |
x: 314, |
|
|
80 |
y: 180, |
|
|
81 |
type: "rect", |
|
|
82 |
stroke: { |
|
|
83 |
color:"#6c3f27", |
|
|
84 |
weight: 1, |
|
|
85 |
opacity:0.3 |
|
|
86 |
}, |
|
|
87 |
fill: { |
|
|
88 |
type: "linear", |
|
|
89 |
rotation: 0, |
|
|
90 |
stops: [ |
|
|
91 |
{color: "#d1c4bd", opacity:0.9, offset: 0}, |
|
|
92 |
{color: "#a78c7e", opacity: 0.9, offset: 0.4}, |
|
|
93 |
{color: "#6c3f27", opacity: 0.9, offset: 0.7} |
|
|
94 |
] |
|
|
95 |
}, |
|
|
96 |
width:142, |
|
|
97 |
height:230 |
|
|
98 |
}); |
|
|
99 |
|
|
|
100 |
var myrect = mygraphic.addShape({ |
|
|
101 |
x: 310, |
|
|
102 |
y: 110, |
|
|
103 |
type: "rect", |
|
|
104 |
stroke: { |
|
|
105 |
color:"#90ad8c", |
|
|
106 |
weight: 1, |
|
|
107 |
opacity:0.6 |
|
|
108 |
}, |
|
|
109 |
fill: { |
|
|
110 |
type: "linear", |
|
|
111 |
rotation: 90, |
|
|
112 |
stops: [ |
|
|
113 |
{color: "#90ad8c", opacity:0.3, offset: 0}, |
|
|
114 |
{color: "#819c7d", opacity: 0.3, offset: 0.8}, |
|
|
115 |
{color: "#40563d", opacity: 0.7, offset: 1.0} |
|
|
116 |
] |
|
|
117 |
}, |
|
|
118 |
width:150, |
|
|
119 |
height:325 |
|
|
120 |
}); |
|
|
121 |
|
|
|
122 |
var reflect = mygraphic.addShape({ |
|
|
123 |
x: 310, |
|
|
124 |
y: 113, |
|
|
125 |
type: "rect", |
|
|
126 |
stroke: { |
|
|
127 |
color:"#90ad8c", |
|
|
128 |
weight: 1, |
|
|
129 |
opacity:0.0 |
|
|
130 |
}, |
|
|
131 |
fill: { |
|
|
132 |
type: "linear", |
|
|
133 |
rotation: 0, |
|
|
134 |
stops: [ |
|
|
135 |
{color: "#fff", opacity:0.0, offset: 0.2}, |
|
|
136 |
{color: "#fff", opacity: 0.4, offset: 0.3}, |
|
|
137 |
{color: "#fff", opacity: 0.0, offset: 0.4} |
|
|
138 |
] |
|
|
139 |
}, |
|
|
140 |
width:150, |
|
|
141 |
height:318 |
|
|
142 |
}); |
|
|
143 |
}); |
|
|
144 |
</script> |
|
|
145 |
|
|
|
146 |
</div> |
|
|
147 |
<h2>HTML</h2> |
|
|
148 |
<pre class="code prettyprint"><div id="mygraphiccontainer"></div></pre> |
|
|
149 |
|
|
|
150 |
|
|
|
151 |
<h2>CSS</h2> |
|
|
152 |
<pre class="code prettyprint">#mygraphiccontainer { |
|
|
153 |
top: 20px; |
|
|
154 |
left: 20px; |
|
|
155 |
position: relative; |
|
|
156 |
width: 680px; |
|
|
157 |
height:500px; |
|
|
158 |
} |
|
|
159 |
.example { |
|
|
160 |
background: url(../assets/graphics/img/curtain.png) no-repeat center; |
|
|
161 |
}</pre> |
|
|
162 |
|
|
|
163 |
|
|
|
164 |
<h2>Javascript</h2> |
|
|
165 |
|
|
|
166 |
<p>Create a <code>Graphic</code> instance</p> |
|
|
167 |
<pre class="code prettyprint">var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"});</pre> |
|
|
168 |
|
|
|
169 |
|
|
|
170 |
<p>Create a radial gradient to act as a shadow for the glass.</p> |
|
|
171 |
|
|
|
172 |
<pre class="code prettyprint">var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}); |
|
|
173 |
var shadow = mygraphic.addShape({ |
|
|
174 |
type: "ellipse", |
|
|
175 |
stroke: { |
|
|
176 |
color: "#ddd", |
|
|
177 |
weight: 0 |
|
|
178 |
}, |
|
|
179 |
fill: { |
|
|
180 |
type: "radial", |
|
|
181 |
stops: [ |
|
|
182 |
{color: "#000", opacity: 0.7, offset: 0}, |
|
|
183 |
{color: "#000", opacity: 0.4, offset: 0.5}, |
|
|
184 |
{color: "#000", opacity: 0.1, offset: 0.7} |
|
|
185 |
], |
|
|
186 |
cx: .6, |
|
|
187 |
cy: .6, |
|
|
188 |
fx: 0.1, |
|
|
189 |
fy: 0.3, |
|
|
190 |
r: 0.8 |
|
|
191 |
}, |
|
|
192 |
width: 280, |
|
|
193 |
height: 20, |
|
|
194 |
x:318, |
|
|
195 |
y:420 |
|
|
196 |
});</pre> |
|
|
197 |
|
|
|
198 |
|
|
|
199 |
<p>Create a rectangle with a linear gradient for the chocolate milk.</p> |
|
|
200 |
|
|
|
201 |
<pre class="code prettyprint">var milk = mygraphic.addShape({ |
|
|
202 |
x: 314, |
|
|
203 |
y: 180, |
|
|
204 |
type: "rect", |
|
|
205 |
stroke: { |
|
|
206 |
color:"#6c3f27", |
|
|
207 |
weight: 1, |
|
|
208 |
opacity:0.3 |
|
|
209 |
}, |
|
|
210 |
fill: { |
|
|
211 |
type: "linear", |
|
|
212 |
rotation: 0, |
|
|
213 |
stops: [ |
|
|
214 |
{color: "#d1c4bd", opacity:0.9, offset: 0}, |
|
|
215 |
{color: "#a78c7e", opacity: 0.9, offset: 0.4}, |
|
|
216 |
{color: "#6c3f27", opacity: 0.9, offset: 0.7} |
|
|
217 |
] |
|
|
218 |
}, |
|
|
219 |
width:142, |
|
|
220 |
height:230 |
|
|
221 |
});</pre> |
|
|
222 |
|
|
|
223 |
|
|
|
224 |
<p>Add another linear gradient rectangle for the glass.</p> |
|
|
225 |
|
|
|
226 |
<pre class="code prettyprint">var myrect = mygraphic.addShape({ |
|
|
227 |
x: 310, |
|
|
228 |
y: 110, |
|
|
229 |
type: "rect", |
|
|
230 |
stroke: { |
|
|
231 |
color:"#90ad8c", |
|
|
232 |
weight: 1, |
|
|
233 |
opacity:0.6 |
|
|
234 |
}, |
|
|
235 |
fill: { |
|
|
236 |
type: "linear", |
|
|
237 |
rotation: 90, |
|
|
238 |
stops: [ |
|
|
239 |
{color: "#90ad8c", opacity:0.3, offset: 0}, |
|
|
240 |
{color: "#819c7d", opacity: 0.3, offset: 0.8}, |
|
|
241 |
{color: "#40563d", opacity: 0.7, offset: 1.0} |
|
|
242 |
] |
|
|
243 |
}, |
|
|
244 |
width:150, |
|
|
245 |
height:325 |
|
|
246 |
});</pre> |
|
|
247 |
|
|
|
248 |
<p>Create the linear gradient for the reflection.</p> |
|
|
249 |
<pre class="code prettyprint">var reflect = mygraphic.addShape({ |
|
|
250 |
x: 310, |
|
|
251 |
y: 113, |
|
|
252 |
type: "rect", |
|
|
253 |
stroke: { |
|
|
254 |
color:"#90ad8c", |
|
|
255 |
weight: 1, |
|
|
256 |
opacity:0.0 |
|
|
257 |
}, |
|
|
258 |
fill: { |
|
|
259 |
type: "linear", |
|
|
260 |
rotation: 0, |
|
|
261 |
stops: [ |
|
|
262 |
{color: "#fff", opacity:0.0, offset: 0.2}, |
|
|
263 |
{color: "#fff", opacity: 0.4, offset: 0.3}, |
|
|
264 |
{color: "#fff", opacity: 0.0, offset: 0.4} |
|
|
265 |
] |
|
|
266 |
}, |
|
|
267 |
width:150, |
|
|
268 |
height:318 |
|
|
269 |
});</pre> |
|
|
270 |
|
|
|
271 |
<h2>Complete Example Source</h2> |
|
|
272 |
<pre class="code prettyprint"><div id="mygraphiccontainer"></div> |
|
|
273 |
<script> |
|
|
274 |
YUI({filter:"raw"}).use('graphics', function (Y) |
|
|
275 |
{ |
|
|
276 |
var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}); |
|
|
277 |
var shadow = mygraphic.addShape({ |
|
|
278 |
type: "ellipse", |
|
|
279 |
stroke: { |
|
|
280 |
color: "#ddd", |
|
|
281 |
weight: 0 |
|
|
282 |
}, |
|
|
283 |
fill: { |
|
|
284 |
type: "radial", |
|
|
285 |
stops: [ |
|
|
286 |
{color: "#000", opacity: 0.7, offset: 0}, |
|
|
287 |
{color: "#000", opacity: 0.4, offset: 0.5}, |
|
|
288 |
{color: "#000", opacity: 0.1, offset: 0.7} |
|
|
289 |
], |
|
|
290 |
cx: .6, |
|
|
291 |
cy: .6, |
|
|
292 |
fx: 0.1, |
|
|
293 |
fy: 0.3, |
|
|
294 |
r: 0.8 |
|
|
295 |
}, |
|
|
296 |
width: 280, |
|
|
297 |
height: 20, |
|
|
298 |
x:318, |
|
|
299 |
y:420 |
|
|
300 |
}); |
|
|
301 |
|
|
|
302 |
var milk = mygraphic.addShape({ |
|
|
303 |
x: 314, |
|
|
304 |
y: 180, |
|
|
305 |
type: "rect", |
|
|
306 |
stroke: { |
|
|
307 |
color:"#6c3f27", |
|
|
308 |
weight: 1, |
|
|
309 |
opacity:0.3 |
|
|
310 |
}, |
|
|
311 |
fill: { |
|
|
312 |
type: "linear", |
|
|
313 |
rotation: 0, |
|
|
314 |
stops: [ |
|
|
315 |
{color: "#d1c4bd", opacity:0.9, offset: 0}, |
|
|
316 |
{color: "#a78c7e", opacity: 0.9, offset: 0.4}, |
|
|
317 |
{color: "#6c3f27", opacity: 0.9, offset: 0.7} |
|
|
318 |
] |
|
|
319 |
}, |
|
|
320 |
width:142, |
|
|
321 |
height:230 |
|
|
322 |
}); |
|
|
323 |
|
|
|
324 |
var myrect = mygraphic.addShape({ |
|
|
325 |
x: 310, |
|
|
326 |
y: 110, |
|
|
327 |
type: "rect", |
|
|
328 |
stroke: { |
|
|
329 |
color:"#90ad8c", |
|
|
330 |
weight: 1, |
|
|
331 |
opacity:0.6 |
|
|
332 |
}, |
|
|
333 |
fill: { |
|
|
334 |
type: "linear", |
|
|
335 |
rotation: 90, |
|
|
336 |
stops: [ |
|
|
337 |
{color: "#90ad8c", opacity:0.3, offset: 0}, |
|
|
338 |
{color: "#819c7d", opacity: 0.3, offset: 0.8}, |
|
|
339 |
{color: "#40563d", opacity: 0.7, offset: 1.0} |
|
|
340 |
] |
|
|
341 |
}, |
|
|
342 |
width:150, |
|
|
343 |
height:325 |
|
|
344 |
}); |
|
|
345 |
|
|
|
346 |
var reflect = mygraphic.addShape({ |
|
|
347 |
x: 310, |
|
|
348 |
y: 113, |
|
|
349 |
type: "rect", |
|
|
350 |
stroke: { |
|
|
351 |
color:"#90ad8c", |
|
|
352 |
weight: 1, |
|
|
353 |
opacity:0.0 |
|
|
354 |
}, |
|
|
355 |
fill: { |
|
|
356 |
type: "linear", |
|
|
357 |
rotation: 0, |
|
|
358 |
stops: [ |
|
|
359 |
{color: "#fff", opacity:0.0, offset: 0.2}, |
|
|
360 |
{color: "#fff", opacity: 0.4, offset: 0.3}, |
|
|
361 |
{color: "#fff", opacity: 0.0, offset: 0.4} |
|
|
362 |
] |
|
|
363 |
}, |
|
|
364 |
width:150, |
|
|
365 |
height:318 |
|
|
366 |
}); |
|
|
367 |
}); |
|
|
368 |
</script></pre> |
|
|
369 |
|
|
|
370 |
</div> |
|
|
371 |
</div> |
|
|
372 |
</div> |
|
|
373 |
|
|
|
374 |
<div class="yui3-u-1-4"> |
|
|
375 |
<div class="sidebar"> |
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
|
379 |
<div class="sidebox"> |
|
|
380 |
<div class="hd"> |
|
|
381 |
<h2 class="no-toc">Examples</h2> |
|
|
382 |
</div> |
|
|
383 |
|
|
|
384 |
<div class="bd"> |
|
|
385 |
<ul class="examples"> |
|
|
386 |
|
|
|
387 |
|
|
|
388 |
<li data-description="Shows how to create a Graphic instance and add shapes."> |
|
|
389 |
<a href="graphics-simple.html">Basic Graphics Implementation</a> |
|
|
390 |
</li> |
|
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
|
394 |
<li data-description="Shows how to draw lines and polygons."> |
|
|
395 |
<a href="graphics-path.html">Basic Path</a> |
|
|
396 |
</li> |
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
|
|
400 |
<li data-description="Shows how to create linear and radial gradient fills."> |
|
|
401 |
<a href="graphics-gradients.html">Create Gradient Fills</a> |
|
|
402 |
</li> |
|
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
|
406 |
<li data-description="Shows how to add drag to a shape."> |
|
|
407 |
<a href="graphics-drag.html">Basic drag with graphic object</a> |
|
|
408 |
</li> |
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
<li data-description="Shows how to apply transforms to shape."> |
|
|
413 |
<a href="graphics-transforms.html">Using Transforms</a> |
|
|
414 |
</li> |
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
<li data-description="Shows how to use a custom shape with the Graphics module."> |
|
|
419 |
<a href="graphics-customshape.html">Custom Shape</a> |
|
|
420 |
</li> |
|
|
421 |
|
|
|
422 |
|
|
|
423 |
|
|
|
424 |
<li data-description="Shows to use the graphics api to draw a realistic glass."> |
|
|
425 |
<a href="graphics-muddyglass.html">Transparent Glass with Shadow</a> |
|
|
426 |
</li> |
|
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
<li data-description="Shows to use the graphics api to draw a violin."> |
|
|
431 |
<a href="graphics-violin.html">Complex Drawing: Violin</a> |
|
|
432 |
</li> |
|
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
|
436 |
|
|
|
437 |
</ul> |
|
|
438 |
</div> |
|
|
439 |
</div> |
|
|
440 |
|
|
|
441 |
|
|
|
442 |
|
|
|
443 |
<div class="sidebox"> |
|
|
444 |
<div class="hd"> |
|
|
445 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
446 |
</div> |
|
|
447 |
|
|
|
448 |
<div class="bd"> |
|
|
449 |
<ul class="examples"> |
|
|
450 |
|
|
|
451 |
|
|
|
452 |
|
|
|
453 |
|
|
|
454 |
|
|
|
455 |
|
|
|
456 |
|
|
|
457 |
|
|
|
458 |
|
|
|
459 |
|
|
|
460 |
|
|
|
461 |
|
|
|
462 |
|
|
|
463 |
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
|
|
|
467 |
|
|
|
468 |
<li data-description="This example demonstrates animating an element along a curved path using bezier control points."> |
|
|
469 |
<a href="../anim/curve.html">Animating Along a Curved Path</a> |
|
|
470 |
</li> |
|
|
471 |
|
|
|
472 |
|
|
|
473 |
</ul> |
|
|
474 |
</div> |
|
|
475 |
</div> |
|
|
476 |
|
|
|
477 |
</div> |
|
|
478 |
</div> |
|
|
479 |
</div> |
|
|
480 |
</div> |
|
|
481 |
|
|
|
482 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
483 |
<script>prettyPrint();</script> |
|
|
484 |
|
|
|
485 |
<script> |
|
|
486 |
YUI.Env.Tests = { |
|
|
487 |
examples: [], |
|
|
488 |
project: '../assets', |
|
|
489 |
assets: '../assets/graphics', |
|
|
490 |
name: 'graphics-muddyglass', |
|
|
491 |
title: 'Transparent Glass with Shadow', |
|
|
492 |
newWindow: '', |
|
|
493 |
auto: false |
|
|
494 |
}; |
|
|
495 |
YUI.Env.Tests.examples.push('graphics-simple'); |
|
|
496 |
YUI.Env.Tests.examples.push('graphics-path'); |
|
|
497 |
YUI.Env.Tests.examples.push('graphics-gradients'); |
|
|
498 |
YUI.Env.Tests.examples.push('graphics-drag'); |
|
|
499 |
YUI.Env.Tests.examples.push('graphics-transforms'); |
|
|
500 |
YUI.Env.Tests.examples.push('graphics-customshape'); |
|
|
501 |
YUI.Env.Tests.examples.push('graphics-muddyglass'); |
|
|
502 |
YUI.Env.Tests.examples.push('graphics-violin'); |
|
|
503 |
YUI.Env.Tests.examples.push('curve'); |
|
|
504 |
|
|
|
505 |
</script> |
|
|
506 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
507 |
|
|
|
508 |
|
|
|
509 |
|
|
|
510 |
</body> |
|
|
511 |
</html> |