2011-06-11 20 views
-1

我創建了名爲'nav'的Raphaeljs元素的set()。我試圖改變所述元件的attr()mousemove,但由於某些原因,set()回來與Array length 0 ......Raphael和更改一組元素的attr()(範圍之外?)

這裏有一個可用的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

你意有所指在runNavigation

+0

真棒意味着nav.push(navButton),謝謝 – 2011-06-11 11:04:54