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
| let paper = Raphael('view', 350, 200); let rect = paper.rect(0, 0, 300, 200); rect.attr({fill: 'white'}); let text = null;
rect.click(function (event, x, y) { console.log('Click event: ', event, x, y); if (text != null) { text.remove(); } text = paper.text(325, 10, "(" + event.layerX + "," + event.layerY + ")"); });
rect.dblclick(function (event, x, y) { if (rect.attr("fill") === 'white') { rect.attr({fill: 'gray'}); } else { rect.attr({fill: 'white'}); } });
circle = paper.circle(50, 50, 20).attr({fill: 'white'}); circle.drag(function (dx, dy, x, y, event) { console.log('On move: ', dx, dy, x, y, event); circle.attr("cx", event.layerX); circle.attr("cy", event.layerY); }, function (x, y, event) { console.log('Move start: ', x, y, event) }, function (event) { console.log('Move end: ', event); });
circle.hover(function (event, x, y) { console.log('Hover in: ', event, x, y); circle.attr('fill', 'red'); }, function (event, x, y) { console.log('Hover out: ', event, x, y); circle.attr('fill', 'white'); });
|