0

スー...ほとんど初心者です。明らかな間違いがあれば、私を気の毒に思います。

Raphaël を使用して、クリック可能な (またはできない) 形状を作成しようとしています。

ただし、実際のレンダリング方法を柔軟にしたいので、ラファエル形状の配列だけでなく、ラファエル形状を含むオブジェクトにしたくありません。

基本的に、オブジェクトのプロパティから図面を分離しようとしています。

以下の私の非動作の試み:

var Box = function (where, type, id) {
    // This is the object containing rendering info

    this.id = id

    this.posx = coords.topLeft.x;
    this.posy = coords.topLeft.y;

    this.width = type.w; // length 
    this.height = type.h; // height 

    this.color = baseColors.black;
    this.line = baseColors.white;

    this.paper = where;

    this.raphShp = this.drawMe()
    this.clickMe()  
}

Box.prototype.drawMe = function () {
    // Function to be called for drawing the shape 
    var box = this.paper.rect(this.posx, this.posy, this.width, this.height);
    box.attr({fill: this.color,stroke: this.line,'stroke-width': '1','stroke-opacity': '1'}).data('name', 'box' + this.id);

    // trying to pass the raphael shape back to the object
    return this.paper.getById(box.id)
}

Box.prototype.clickMe = function () {
    // trying to add clickable property to the shape
        this.raphShp.click(function(evt) {
            this.rotate(45);
            console.log('rotate')
        }); 
}

drawMe にクリック可能なプロパティを追加することはもちろん機能します。しかし、私はそれを別々にできるようにしたいです。

私が見逃している痛々しいほど明らかなことは何ですか?

4

1 に答える 1

0

このコードは私のために働いた: http://jsfiddle.net/89dL5/2/

オブジェクトをインスタンス化することを忘れないでください:

var b = new Box(Raphael(100, 100, 500, 500), [etc], [etc]);

おそらく、コードのどこかで間違ったことをしているでしょう。

于 2013-04-06T16:06:43.733 に答える