그런 어리석은 질문과 아마도 간단한 대답을 가지고 있지만 내 캔버스 주위에 내 이미지를 드래그 할 수 없습니다.rect/image에 드래그를 적용하려면 어떻게해야합니까?
function simpleButton(origImage, overlay, iconWidth, iconHeight, xpos, ypos, whenClicked, title)
{
svg.append("svg:image")
.datum({
x: xpos, //-starting 'x' position
y: ypos //-starting 'y' position
})
.attr("x", function (d) { return d.x; })
.attr("y", function (d) { return d.y; })
.attr("xlink:href", origImage) //-original image
// .attr("x",xpos) //-starting 'x' position
// .attr("y",ypos) //-starting 'y' position
.attr("width",iconWidth) //-icon width
.attr("height",iconHeight) //-icon height
.on("click",whenClicked) //-call when button is clicked
.on("mouseover",function(){d3.select(this).attr("xlink:href", overlay);}) //-change image when mouseover
.on("mouseout",function(){d3.select(this).attr("xlink:href", origImage);}) //-reset image
.call(button_drag)
.append("svg:title")
.text(title); //-give the button a title
}
그리고 내 드래그 기능 : 이미지 중 하나를 드래그 할 때 나는 오류가
var button_drag = d3.behavior.drag()
.on("dragstart", function(){
clog("dragstart");
})
.on("drag", function(d,i) {
d.x += d3.event.dx
d.y += d3.event.dy
d3.select(this).attr("transform", function(d,i){
return "translate(" + [ d.x,d.y ] + ")"
})
})
.on("dragend", function(){
clog("dragend");
});
:
Uncaught TypeError: Cannot read property 'x' of undefined
내가 시도 여기에 내 이미지에 대한 내 코드입니다 그것을 연구하고 분명히 데이터를 내 사각형에 적용 할 필요가 없습니다. 이 문제를 어떻게 해결할 수 있습니까?
달콤한. 대답에 대한 환호. 일종의 일이야. ive 위의 코드를 업데이트했습니다. 내가 가지고있는 것은 재사용 할 수 있도록 단추를 만드는 함수입니다. 그러나 버튼의 움직임은 꺼져 있습니다. 즉, 노드를 드래그하면 오른쪽으로 1500 픽셀 정도 변환되지만 대다수는 1 픽셀 만 번역하면 약 400 픽셀이됩니다. 어떤 아이디어? @meetamit – rekoDolph
'd.x'가 누적되는 방식은 아마도 올바르지 않을 것입니다. 'd.x + = d3.event.dx'를 사용하는 대신에'd.x = mouse [0]'과 ('d.y = mouse [1]')을 사용하십시오. 'var mouse = d3.mouse (this.parentNode);'@reko – meetamit
을 사용하여 마우스 위치를 얻으려면 모두 제대로 작동합니다. 다시 한 번 감사드립니다 :) – rekoDolph