3

嗨,我有一个下拉菜单,每当我更改下拉菜单中的选项时,我都想更改画布中的内容...例如

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

在我的下拉列表中,我将有两个选项“小矩形”和“大矩形”。我想在下拉选择中调用相应的函数。我面临的问题是,一旦我更改下拉选项,Raphael 似乎并没有画出来。我从 stackoverflow 中的一些问题中读到,没有必要在 RaphaelJS 中使用重绘技术 查看答案

即使我尝试这种方式:

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

1 回答 1

5

无需再次重绘矩形......

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

希望对你有所帮助...

于 2012-07-24T20:02:13.393 回答