HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
function getRandomColor() {
2
var min = Math.ceil(50);
3
var max = Math.floor(200);
4
var red = Math.floor(Math.random() * (max - min)) + min;
5
var green = Math.floor(Math.random() * (max - min)) + min;
6
var blue = Math.floor(Math.random() * (max - min)) + min;
7
return "rgb(" + red + "," + green + "," + blue + ")";
8
}
9
10
var stage = acgraph.create("container");
11
12
var layer = stage.layer();
13
layer.rect(0, 0, 500, 300).fill("#FFFFFF 0.01");
14
15
var textObject = layer.text(70, 55, "Click on this TEXT");
16
textObject.style({fontSize: "18px"});
17
textObject.selectable(false);
18
19
var counter = 0;
20
21
textObject.listen("click", function (e) {
22
counter++;
23
textObject.text("You clicked " + counter + " times. " + "Click again");
24
25
// Stop propagation.
26
e.stopPropagation();
27
});
28
29
layer.listen("click", function (e) {
30
textObject.color(getRandomColor());
31
});