【发布时间】:2015-06-19 06:45:01
【问题描述】:
我正在使用 Raphael 在不同的图层中绘制不同的形状。我想实现 CSS z-index 分层,以便无论首先执行哪个函数(draw_rect、draw_circle 或 draw_line),矩形都位于最底层,线条位于中间,圆圈位于最顶层。这是我尝试过的:
draw_rect(10, 10, 180, 180);
draw_circle(100, 100, 60);
draw_line();
function draw_rect(x, y, width, height) {
var rect = paper.rect(x, y, width, height);
rect.attr({
fill: 'red',
position: 'absolute',
'z-index': 1
});
}
function draw_circle(x, y, radius) {
var circ = paper.circle(x, y, radius);
circ.attr({
fill: 'green',
position: 'absolute',
'z-index': 3
});
}
function draw_line() {
var line = paper.path("M0,0L200,200");
line.attr({
'stroke': 'blue',
position: 'absolute',
'z-index': 2
});
}
我不能使用 element.tofront() 和 element.toback() 因为表达式只将元素带到顶层/底层(而不是中间层)。所以,如果有人能启发我做 z-index 分层,我会感谢永恒:D
【问题讨论】:
标签: javascript html css raphael z-index