6

如何从免费的 Raphael 图标更改图标的宽度和高度?

我试过用attr,试过用%,像这样var paper = Raphael("canvas", 100%, 100%);

我需要这样做:如果我改变父块的大小,我的图标大小也会改变。

更新:我尝试使用“缩放”和“变换”,但图标从中心调整大小并且不适合父级

4

1 回答 1

3

根据 Raphael.js 文档

var el = paper.rect(10, 20, 300, 200);
// translate 100, 100, rotate 45°, translate -100, 0
el.transform("t100,100r45t-100,0");
// if you want you can append or prepend transformations
el.transform("...t50,50");
el.transform("s2...");
// or even wrap
el.transform("t50,50...t-50-50");
// to reset transformation call method with empty string
el.transform("");
// to get current value call it without parameters
console.log(el.transform());

检查这个小提琴:所有转换的演示

var icon = paper.rect(100,200,100,100);

var anim = Raphael.animation({
    "10%":{transform:'t100,0'}, //transform on x-axis
    "20%":{transform:'...t0,100'},//transform on y-axis
    "30%":{transform:'...t-100,0'},//transform on x-axis(negative)
    "40%":{transform:'...t0,-100'},//transform on y-axis(negative)
    "50%":{transform:'...t200,200'},//transform diagonally
    "60%":{transform:'...t-100,-100'},//transform diagonally(negative)
    "70%":{transform:'...s1,1.5'},//scale y-axis
    "80%":{transform:'...s1.5,1'},//scale x-axis
    "90%":{transform:'...s2'},//scale in both direction
    "100%":{transform:'...r45'},//rotate
},5000);

icon.animate(anim.delay(1000));

所以在你的情况下,你必须这样做:

var somename = paper.path("路径坐标").transform('s2,3');

其中 2 代表宽度,3 代表高度。

于 2012-12-19T18:10:05.407 回答