2012-04-10 20 views
2

私のプログラムでいくつかのRaphaelオブジェクトを作成する必要があります。 field1とfield2はdiv要素です。 Raphaelの各オブジェクト(paper1、paper2、...)はユニークなキャンバスを持ち、まったく同じ機能を持つ必要があります。 Raphaelオブジェクトは後で動的に作成する必要があります。次のサンプルコードでは、どのオブジェクトがmousedownイベントを起動するかを知る必要があります。私はまた、どのdiv要素(ここでfield1/field2)がmousedownイベントが発生したのかを知りたいと思います。どのように情報を入手できますか?ここでRaphaelオブジェクトへの参照

var myProgram = (function() { 
var paper1 = Raphael("field1", 200, 400, fieldActions); 
var paper2 = Raphael("field2", 200, 400, fieldActions); 

var planeAttrs = { 
    fill: "#fff" 
}; 

function fieldActions(){ 
    var that = this; 

    that.field = that.rect(0, 0, 200, 400, 30); 

    that.field.attr(planeAttrs); 

    that.field.mousedown(function(e) { 
    }); 
}); 
}()); 

答えて

0

あなたが行く:

that.field.mousedown(function(e) { 
    var target = e.target; 
    var svgElem = target.parentNode; 
    var div = svgElem.parentNode; 
    alert(div.id); 
}); 

http://jsfiddle.net/mihaifm/UyPn6/3/

2
that.field.mousedown(function(e) { 
console.log(this, this.node, this.paper.canvas, this.paper.canvas.parentNode) 
}); 

this - 矩形のラファエルオブジェクト

this.node - RECT SVGのDOM要素

this.paper.canvas - svg dom要素

this.paper.canvas.parentNode -did(field2/field1)は、クリックされたsvgを含みます。

関連する問題