拉斐尔和改变一组元素的attr()(超出范围?)

时间:2011-06-11 10:13:08

标签: javascript jquery html5 canvas raphael

我创建了一个名为'nav'的set() Raphaeljs元素。我正在尝试更改attr()上所述元素的mousemove,但出于某种原因,set()会返回Array length 0 ...

这里有一个JSFiddle: 的 http://jsfiddle.net/neuroflux/g8wHa/1/

这是循环和功能的片段:

function init() {
                sketch = Raphael(10, 10, 800, 600);
                nav = sketch.set();
                runNavigation();
                document.addEventListener('mousemove',checkMouse);
            };

            function runNavigation() {
                for (var a = 0; a < 5; a++) {
                    navButton = sketch.rect(navX + (a*105), 10, 100, 100, 32, 32).attr({
                        stroke:'#666',
                        fill:'#dedede'
                    }).click(function(){
                        alert(0);
                    });
                    nav.push = navButton;
                }
            };

            function checkMouse(e) {
                mX = e.pageX;
                mY = e.pageY;

                /* This section is broken... */
                /* It says the Array's length is 0 */
                console.log('x: '+mX);
                console.log('y: '+mY);
                console.log('Element: ');
                console.log(nav);
                nav.attr({
                    y:mX/2,
                    x:mY/2
                });
                /*****************************/
            };

提前致谢!

1 个答案:

答案 0 :(得分:1)

您必须在nav.push(navButton)

中使用runNavigation