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
var stage = acgraph.create("container");
2
3
layer = stage.layer();
4
5
layer.rect(0, 0, 500, 300).fill("#FFFFFF 0.01");
6
7
var textObject = layer.text(70, 55, "Click on this TEXT");
8
textObject.style({fontSize: "18px"});
9
textObject.selectable(false);
10
11
var counter = 0;
12
13
// Adds an event listener to a text
14
textObject.listen("click", function(e) {
15
counter++;
16
textObject.text("You clicked " + counter + " times. Click again.");
17
e.stopPropagation();
18
});
19
20
// Adds an event listener to a layer
21
layer.listen("click", function(e) {
22
// change text color
23
textObject.color(getRandomColor());
24
});
25
26
function getRandomColor() {
27
min = Math.ceil(50);
28
max = Math.floor(200);
29
red = Math.floor(Math.random() * (max - min)) + min;
30
green = Math.floor(Math.random() * (max - min)) + min;
31
blue = Math.floor(Math.random() * (max - min)) + min;
32
return "rgb("+ red + "," + green + "," + blue + ")";
33
}