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 wrapper propagation.
26
e.stopWrapperPropagation();
27
});
28
29
layer.listen('click', function (e) {
30
counter++;
31
textObject.text('You clicked ' + counter + ' times. ' + 'Click again');
32
textObject.color(getRandomColor());
33
});
34
35
acgraph.events.listen(document.getElementById('container'), 'click', function (e) {
36
counter++;
37
textObject.text('You clicked ' + counter + ' times. ' + 'Click again');
38
textObject.color(getRandomColor());
39
});