简体   繁体   中英

drag() on array-elements in raphael.js

I have a lot of Raphael elements which I push into an array:

var start = function () {
                this.ox = this.attr("cx");
                this.oy = this.attr("cy");
            },
            move = function (dx, dy) {
                this.attr({cx: this.ox + dx, cy: this.oy + dy});
            }    

for(var i = 0; i < 149; i++) {
    cubes = paper.rect(Math.floor(Math.random()*2000), Math.floor(Math.random()*2000), 0, 0);
    cubes.animate({ width: 25, height: 25 }, 500, "bounce");
    cubesmixed.push(cubes);
    cubesmixed[i].drag(move, start);
}

but unfortunatly I can't drag them. The most weird thing is, that start and move fire as they should. But why do they don't move.

Thanks in advance!

First of all attribute cx, cy are used in circles and elipsis so updating them will not move your rectangle which uses x and y attributes. If what you want to achieve is to move them simultanously (that was my first impression when I started to read your question - but I am not sure about that anymore :)), then please refer to this question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM