gpt4 book ai didi

jquery - 单击元素时绘制元素的边界框 RaphaelJS

转载 作者:行者123 更新时间:2023-12-01 03:16:26 25 4
gpt4 key购买 nike

因此,我尝试对元素/集使用 getBBox() 方法,并使用 x、y、width 和 height 属性来定义矩形。然而该元素附加了一个拖动事件,每次触发拖动事件时,它都会绘制一个新的边界框。

我尝试在拖动功能后使用 element.remove 来删除该元素,但我似乎收到了元素未定义的错误。

foo.click(function(){
console.log(foo.getBBox());
var herpaderp = drawBBox(foo.getBBox());
console.log(herpaderp);
dragsymbolsoncanvas(foo,herpaderp);
});
function dragsymbolsoncavas(foo,herpaderp){
function dragger(){
this.dx = this.dy = 0;
};
function mover(s){
return function(dx, dy){
if(this.data("candrag")=="true"){
(s||this).translate(dx-this.dx,dy-this.dy);
this.dx = dx;
this.dy = dy;
}
}
};
foo.drag(mover(foo), dragger);
herpaderp.remove();
};

最佳答案

JSFiddle 示例: http://jsfiddle.net/hu8dd/

var Paper = Raphael("test",500,500);
var foo = Paper.circle(100,100,50).attr({fill: "#aa5555"});

var onstart = function(){
if(this.rect == undefined){
var coords = this.getBBox();
this.rect = Paper.rect(coords.x, coords.y, coords.width, coords.height)
.attr({fill: "none", stroke: "#aaaaaa", "stroke-width": 1});
}else{
this.rect.show();
}

};
var onmove = function(dx,dy){
this.transform(this.trans+'T'+(dx)+','+(dy));
this.rect.transform(this.rtrans+'T'+(dx)+','+(dy));

};
var onend = function(){
this.rect.hide();
this.trans = this.transform();
this.rtrans = this.rect.transform();
}

foo.drag(onmove, onstart, onend);

关于jquery - 单击元素时绘制元素的边界框 RaphaelJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15635419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com