2012-07-24 57 views
3

您好我有一個下拉菜單&每當我改變我想改變畫布內容的下拉選項...例如RaphaelJS問題... DRAW還是REDRAW?

var paper = Raphael("myDivID",400,400); 
function smallRectangle(){ 
    paper.rect(10,10,100,50); 
} 
function bigRectangle(){ 
    paper.rect(10,10,150,100); 
} 

在我的下拉我有兩種選擇「小矩形「&」大矩形「。我想在下拉選擇中調用相應的功能。我面臨的問題是,一旦我改變下拉選項拉斐爾似乎並沒有繪製它。 我已經閱讀了一些在stackoverflow的問題,沒有必要使用重繪技術在RaphaelJS See the Answer

即使我嘗試這樣:

var paper = Raphael("myDivID",400,400); 
function smallRectangle(){ 
    paper.clear() 
    paper.rect(10,10,100,50); 
} 
function bigRectangle(){ 
    paper.clear() 
    paper.rect(10,10,150,100); 
} 

這似乎並不在clear()功能後,將元素添加到畫布上。畫布保持空白。
供參考:我的代碼非常大,所以我在這裏發佈了這個簡單的例子。

回答

4

沒有必要重繪再次RECT ....

function resize_Rect(rect,newWidth,newHeight){//passing rect ,new width and new height 
     rect.attr({'width':newWidth,'height':newHeight}); 
       } 

希望它可以幫助你了...

+0

非常感謝!你救了我的一天:) – 2012-07-25 06:28:48

+0

不客氣,我的榮幸! :) – Aukhan 2012-07-25 17:55:25