Raphael 和集合内的目标节点

发布于 2024-11-10 11:18:48 字数 1949 浏览 1 评论 0原文

我有一组拉斐尔图像,它们被随机放置在画布上。我希望这些图像中的每一个都有翻转,但我认为我的语法错误:( 有什么想法吗?

JSFiddle: http://jsfiddle.net/neuroflux/VS6gT/1/(编辑以包含库)

代码片段:

for (var i = 0; i <= a; i++) {
                    var ax = Math.floor(Math.random() * dw) + 1;
                    var ay = Math.floor(Math.random() * dh) + 1;
                    var ao = Math.floor(Math.random() * 10) + 1;
                    var ac = Math.floor(Math.random() * 4) + 1;
                    if (ac == 1) { col = 'earth.gif'; } else 
                    if (ac == 2) { col = 'jupiter.gif'; } else 
                    if (ac == 3) { col = 'neptune.gif'; }
                    var planetName = nameGen();
                    st.push = (
                        planet = r.image(col, ax,ay,ac,ac).attr({
                            'fill':'#fff',
                            'opacity':'0.'+ao,
                            'stroke-width':0,
                            'cursor':'pointer'
                        }).id = planetName
                    );
                }

st.mouseover(function() {
                    if (info) { info.remove(); }
                    this.node.animate({
                        'scale':30
                    }, 250);
                    this.animate({
                        'rotation':999
                    }, 25000);
                    info = r.rect(5,5,200,150).attr({
                        'fill':'#fff',
                        'stroke':'#ff0000'
                    });
                    infoText = r.text(75,25,'PLANET NAME: \r\n'+this.id+'\r\n\r\nDISTANCE: \r\n'+(1.0 - this.attr('opacity'))*10).attr({
                        'font-size':14
                    });
                }).mouseout(function() {
                    this.animate({
                        'scale':1
                    }, 250);
                });

I have a set of Raphael Images that are being put at random on the canvas. I would like each of these images to have a rollover but I think I have my syntax wrong :( any ideas?

JSFiddle: http://jsfiddle.net/neuroflux/VS6gT/1/ (Edited to include the libraries)

Code Snippet:

for (var i = 0; i <= a; i++) {
                    var ax = Math.floor(Math.random() * dw) + 1;
                    var ay = Math.floor(Math.random() * dh) + 1;
                    var ao = Math.floor(Math.random() * 10) + 1;
                    var ac = Math.floor(Math.random() * 4) + 1;
                    if (ac == 1) { col = 'earth.gif'; } else 
                    if (ac == 2) { col = 'jupiter.gif'; } else 
                    if (ac == 3) { col = 'neptune.gif'; }
                    var planetName = nameGen();
                    st.push = (
                        planet = r.image(col, ax,ay,ac,ac).attr({
                            'fill':'#fff',
                            'opacity':'0.'+ao,
                            'stroke-width':0,
                            'cursor':'pointer'
                        }).id = planetName
                    );
                }

st.mouseover(function() {
                    if (info) { info.remove(); }
                    this.node.animate({
                        'scale':30
                    }, 250);
                    this.animate({
                        'rotation':999
                    }, 25000);
                    info = r.rect(5,5,200,150).attr({
                        'fill':'#fff',
                        'stroke':'#ff0000'
                    });
                    infoText = r.text(75,25,'PLANET NAME: \r\n'+this.id+'\r\n\r\nDISTANCE: \r\n'+(1.0 - this.attr('opacity'))*10).attr({
                        'font-size':14
                    });
                }).mouseout(function() {
                    this.animate({
                        'scale':1
                    }, 250);
                });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹微笑 2024-11-17 11:18:48

似乎将事件附加到集合中不起作用,但您可以在创建它们时将它们直接附加到行星:

var planet = r.image(col, ax,ay,ac,ac).attr({
        'fill':'#fff',
        'opacity':'0.'+ao,
        'stroke-width':0,
        'cursor':'pointer'
});
planet.id = planetName;
st.push = planet;
planet.mouseover(function() {
    if (info) { info.remove(); }
    this.animate({
        'scale':30
    }, 250);
    this.animate({
        'rotation':999
    }, 25000);
    info = r.rect(5,5,200,150).attr({
        'fill':'#fff',
        'stroke':'#ff0000'
    });
    infoText = r.text(75,25,'PLANET NAME: \r\n'+this.id+'\r\n\r\nDISTANCE: \r\n'+(1.0 - this.attr('opacity'))*10).attr({
        'font-size':14
    });
}).mouseout(function() {
    this.animate({
        'scale':1
    }, 250);
    });
}

我必须更改的唯一其他事情是 this.node.animatethis.animate那么它似乎可以工作

It seems like attaching events to the set doesn't work, but you can attach them direct to the planets as you're creating them:

var planet = r.image(col, ax,ay,ac,ac).attr({
        'fill':'#fff',
        'opacity':'0.'+ao,
        'stroke-width':0,
        'cursor':'pointer'
});
planet.id = planetName;
st.push = planet;
planet.mouseover(function() {
    if (info) { info.remove(); }
    this.animate({
        'scale':30
    }, 250);
    this.animate({
        'rotation':999
    }, 25000);
    info = r.rect(5,5,200,150).attr({
        'fill':'#fff',
        'stroke':'#ff0000'
    });
    infoText = r.text(75,25,'PLANET NAME: \r\n'+this.id+'\r\n\r\nDISTANCE: \r\n'+(1.0 - this.attr('opacity'))*10).attr({
        'font-size':14
    });
}).mouseout(function() {
    this.animate({
        'scale':1
    }, 250);
    });
}

The only other thing I had to change was this.node.animate to this.animate, then it seems to be working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文