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
<style scoped>
#custom-doc { width: 95%; min-width: 950px; }
#pagetitle {background-image: url(../../assets/bg_hd.gif);}
#mygraphiccontainer {
top: 20px;
left: 20px;
position: relative;
width: 680px;
height:500px;
}
.example {
background: url(../assets/graphics/img/curtain.png) no-repeat center;
}
</style>
<div class="intro">
<p>
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.
</p>
</div>
<div class="example">
{{>graphics-muddyglass-source}}
</div>
<h2>HTML</h2>
```
<div id="mygraphiccontainer"></div>
```
<h2>CSS</h2>
```
#mygraphiccontainer {
top: 20px;
left: 20px;
position: relative;
width: 680px;
height:500px;
}
.example {
background: url(../assets/graphics/img/curtain.png) no-repeat center;
}
```
<h2>Javascript</h2>
<p>Create a `Graphic` instance</p>
```
var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"});
```
<p>Create a radial gradient to act as a shadow for the glass.</p>
```
var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"});
var shadow = mygraphic.addShape({
type: "ellipse",
stroke: {
color: "#ddd",
weight: 0
},
fill: {
type: "radial",
stops: [
{color: "#000", opacity: 0.7, offset: 0},
{color: "#000", opacity: 0.4, offset: 0.5},
{color: "#000", opacity: 0.1, offset: 0.7}
],
cx: .6,
cy: .6,
fx: 0.1,
fy: 0.3,
r: 0.8
},
width: 280,
height: 20,
x:318,
y:420
});
```
<p>Create a rectangle with a linear gradient for the chocolate milk.</p>
```
var milk = mygraphic.addShape({
x: 314,
y: 180,
type: "rect",
stroke: {
color:"#6c3f27",
weight: 1,
opacity:0.3
},
fill: {
type: "linear",
rotation: 0,
stops: [
{color: "#d1c4bd", opacity:0.9, offset: 0},
{color: "#a78c7e", opacity: 0.9, offset: 0.4},
{color: "#6c3f27", opacity: 0.9, offset: 0.7}
]
},
width:142,
height:230
});
```
<p>Add another linear gradient rectangle for the glass.</p>
```
var myrect = mygraphic.addShape({
x: 310,
y: 110,
type: "rect",
stroke: {
color:"#90ad8c",
weight: 1,
opacity:0.6
},
fill: {
type: "linear",
rotation: 90,
stops: [
{color: "#90ad8c", opacity:0.3, offset: 0},
{color: "#819c7d", opacity: 0.3, offset: 0.8},
{color: "#40563d", opacity: 0.7, offset: 1.0}
]
},
width:150,
height:325
});
```
<p>Create the linear gradient for the reflection.</p>
```
var reflect = mygraphic.addShape({
x: 310,
y: 113,
type: "rect",
stroke: {
color:"#90ad8c",
weight: 1,
opacity:0.0
},
fill: {
type: "linear",
rotation: 0,
stops: [
{color: "#fff", opacity:0.0, offset: 0.2},
{color: "#fff", opacity: 0.4, offset: 0.3},
{color: "#fff", opacity: 0.0, offset: 0.4}
]
},
width:150,
height:318
});
```
<h2>Complete Example Source</h2>
```
{{>graphics-muddyglass-source}}
```