2012-01-02 87 views
0

一個元素根據這個問題 Raphael - event when mouse near element的MouseEvent當拉斐爾

靠近我創建一個圍繞另一個矩形, 當鼠標在大型矩形一個看不見的矩形,圓將出現。 但由於大矩形位於小矩頂部,所以當鼠標位於小矩形上時,我無法處理另一個事件。

(如果小矩形位於頂部,當我到達小矩形時,該點將消失) 而且我還希望在圓形區域有另一個事件。

對此有任何解決方案? 海爾是模仿較大的矩形的事件與一個較小的code

+0

喜歡這個? http://jsfiddle.net/qZKHM/11/ – Joe 2012-01-02 18:08:47

+0

這樣一個簡單的解決方案,謝謝。如果你在下面再次發佈答案,我可以接受你的答案。 – tomen 2012-01-02 18:20:14

+0

太棒了,很高興幫助 – Joe 2012-01-02 18:24:38

回答

1

類:

var paper = new Raphael(0, 0, 500, 500); 

createRect(100, 100, 100, 50); 

function createRect(x, y, width, height) { 
    var boundrect = paper.rect(x - 30, y - 30, width + 60, height + 60).attr({ 
      "fill": "pink", 
      "stroke": "none" 
     }).mouseover(function(event) { 
      topCtrl.show() 
     }).mouseout(function(event) { 
      topCtrl.hide() 
     }) 

     , 

     rect = paper.rect(x, y, width, height).attr({ 
     "fill": "white", 
     "stroke": "red" 
    }).mouseover(function(event) { 
     topCtrl.show(); 
     topCtrl.attr({ 
      "fill": "white" 
     }) 
    }), 
     topCtrl = paper.circle(x + (width/2), y, 5).attr({ 
      "fill": "red" 
     }); 
}