微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 如何更改raphael图标的大小?

如何从免费的拉斐尔图标改变图标的​​宽度和高度?

我试图使用attr,试图使用%,就像这篇var paper = Raphael(“canvas”,100%,100%);

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

upd:我尝试使用“scale”和“transform”,但是图标从中心调整大小并且不能正确地适合父级

最佳答案
根据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());

Check this Fiddle
演示所有变换

var icon = paper.rect(100,200,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,//transform on x-axis(negative)
    "40%":{transform:'...t0,-100'},//transform on y-axis(negative)
    "50%":{transform:'...t200,200'},//transform diagonally
    "60%":{transform:'...t-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(“path coordinates”).transform(‘s2,3’);

其中2是宽度和宽度3是高度.

原文地址:https://www.jb51.cc/css/427531.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。