我有一个矩形,我把它旋转到-45,但是在拖动时,旋转是不适用的。
代码:
function createPoly(x, y)
{
var width = 41;
var height = 41;
var centreX = width / 2;
var centreY = height / 2;
var shape = d3.select(this);
var poly = svg.append("g")
.classed("bpmnGateway", true)
.append('svg:rect')
.attr("type", "poly")
.attr("x", (x - centreX))
.attr("y", (y - centreY))
.attr("width", 41)
.attr("height", 41)
.attr("transform", "rotate(-45)")
.attr("stroke-width", "1.5px")
.attr("stroke", "#7E7E7E")
.style('cursor', 'move')
.style("fill", "#FFED6B")
.call(drag);
}
function drag()
{
if (shape.attr('type') === 'poly')
{
translate = d3.transform(shape.attr("transform")).translate;
var x = d3.event.dx + translate[0];
var y = d3.event.dy + translate[1];
shape.attr("transform", "rotate(-45)")
shape.attr("transform", "translate(" + x + "," + y + ")");
}
}我尝试了旋转选项,内部拖动功能,但没有工作。我怎么才能让它起作用?
发布于 2015-08-13 12:06:11
第二个attr函数覆盖第一个。你可以同时做这两件事。
shape.attr("transform", "rotate(-45) translate(" + x + "," + y + ")");或
shape.attr("transform", "translate(" + x + "," + y + ") rotate(-45)");根据您希望应用转换的顺序而定。
https://stackoverflow.com/questions/31987674
复制相似问题