2

我有一个矩形,它在 mousedown 事件时发光,并且在 mouseup 事件时发光消失。问题是当我拖动矩形时,画布上仍然存在发光!

为了清楚起见,这是我的代码:

window.onload = function(){
        var paper = new Raphael("holder",500,500);

        var myRect = paper.rect(200,200,200,100,10);
        myRect.attr({
            fill: "#999",
            stroke: "#555",
            'stroke-width': 5
        });

        myRect.mousedown(function(){
                this.g = myRect.glow();
            }
        );
        myRect.mouseup(function(){
                this.g.remove();
        });
        var start = function(){
            this.ox = this.attr('x');
            this.oy = this.attr('y');
        },
        move = function(dx,dy){
            var att = {x:this.ox+dx,y:this.ox+dy};
            this.attr(att);
        },
        up = function(){
            //
        };
        myRect.drag(move,start,up);
    }
4

2 回答 2

3

您可以移除对象的辉光start并再次将其应用到 上up。这样,当您拖动对象时,阴影将不可见,但在您放下对象时会出现。

这是您的示例的小提琴

于 2013-03-29T10:56:49.867 回答
1

首先,你不应该this在匿名函数中使用,因为它的作用域this只是在那里可用。

其次,您不需要myRect.mousedown并且myRect.mouseup因为您处理那些我们在您的myRect.drag(startup)中的回调

所以我给你做了一个小提琴,你可以看到它在工作。

PS定位似乎还有另一个错误:当您拖动几次时,矩形会远离光标。

于 2012-07-20T15:35:23.790 回答