我是新的拉斐爾JS和我測試一些關於它。 我必須創建一個路徑並將其拖動。拉斐爾JS拖動路徑,並在紙上保持它
目前沒有問題。
我真正的問題是我必須限制進入紙張的行動。 我的路徑必須是約束移動到我的raphael紙。
(function() {
var trans_x;
var trans_y;
var w = 300;
var h = 300;
var paper = Raphael('holder', w, h);
var rectPath = paper.path("M0, 0L0, 90L90, 90L90, 0Z");
rectPath.attr({
fill: "green",
cursor: "move"
});
var bBox = rectPath.getBBox();
var startPath = function() {
this.ox = this.attr("x");
this.oy = this.attr("y");
},
movePath = function(dx, dy) {
trans_x = dx - this.ox;
trans_y = dy - this.oy;
this.translate(trans_x, trans_y);
this.ox = dx;
this.oy = dy;
},
upPath = function() {};
rectPath.drag(movePath, startPath, upPath);
})();
這是我基本的代碼在小提琴:
http://jsfiddle.net/Drzep/7s8rxhat/4/
我tryed很多事情與math.min和math.max但沒有任何工程的路徑。 我發現如何用raphael circle和rect來做到這一點,但沒有找到路徑。
可以使用setviewBox屬性。 – Ved 2014-12-05 05:37:19
如果你已經可以用圓或矩形做這個,你應該可以在路徑等任何元素上使用getBBox()方法來獲取它的x1,x2,y1,y2點來進行比較。只需運行getBBox()並查看輸出。 – Ian 2014-12-05 08:23:09
感謝您的評論,我之前嘗試過使用getBbox,但發現不一致的結果(我認爲)。你能告訴我,Bbox的x和y結果在這裏是否正常? (Console.log)http://jsfiddle.net/Drzep/7s8rxhat/5/ – cmuller 2014-12-05 10:22:56