我是拉斐尔图书馆的新手(到目前为止看起来很棒)
我想知道如何创建水平线性渐变。
到目前为止,这是我的测试代码,主要基于我一直在研究的示例: -
$(function () {
var paper = Raphael(0, 0, $(window).width(), $(window).height());
var path = paper.path("M800,100 L800,600 Q801,610 802,600 T803,600 L803,100 Q802,110 801,100 T800,100").attr({
"fill": "90-#f00:5-#00f:100",
"fill-opacity": 0.5
});
var pathArray = path.attr("path");
handle = paper.circle(pathArray[0][1], 350, 5).attr({
fill: "black",
cursor: "pointer",
"stroke-width": 1,
stroke: "transparent"
});
var start = function () {
this.cx = this.attr("cx"),
this.cy = this.attr("cy");
},
move = function (dx, dy) {
var X = this.cx + dx, Y = this.cy + dy;
this.attr({ cx: X, cy: Y });
pathArray[0][1] = pathArray[1][1] = pathArray[6][1] = X;
path.attr({ path: pathArray });
},
up = function () {
this.dx = this.dy = 0;
};
handle.drag(move, start, up);
});
我从w3网站上的SVG规范看到实际的linearGradient标签中有一个x1,x2,y1,y2属性(虽然我甚至不确定它们是否处理方向?http://www.w3.org/TR/SVG/pservers.html#LinearGradientElement)。< / p>
我还没有充分利用Raphael知道如何在我的路径属性中设置它。
干杯, wacka。
P.S。 编辑:添加以下帮助,但仅适用于IE: -
$("linearGradient").attr("x1", "0");
$("linearGradient").attr("x2", "100%");
$("linearGradient").attr("y1", "0");
$("linearGradient").attr("y2", "0");
另一个编辑:有趣的是,上面只适用于IE,但以下两种方法都有效(即使HTML是相同的): -
$("defs").children().attr("x1", "0");
$("defs").children().attr("x2", "100%");
$("defs").children().attr("y1", "0");
$("defs").children().attr("y2", "0");
出于某种原因,以下是IE中的1和铬中的0: -
$("lineargradient").length
现在,虽然这有效,但肯定有更好的方法吗?
答案 0 :(得分:2)
以下是具有水平和垂直渐变的rect的示例。
paper.rect(100,100,200,200).attr({"fill":"0-#f00:5-#00f:100"});
paper.rect(300,300,200,200).attr({"fill":"90-#f00:5-#00f:100"});
填充中的第一个值是渐变的角度。您可以将其应用到您的路径中。