简体   繁体   English

使用Raphael.js转换SVG路径

[英]Transforming an SVG path using Raphael.js

I am new to SVG and Raphael.js, so while the code I have written works as I expected/wanted, I want to check if what I have done is best practice/the right way, or if there is a better way. 我是SVG和Raphael.js的新手,所以虽然编写的代码可以按我的期望/期望工作,但是我想检查是否做的是最佳实践/正确的方法,或者是否有更好的方法。

I have a path, it's basically an off-circle (as per the brand). 我有一条路,基本上是一个圈(根据品牌)。 I got the path by converting a PNG to SVG (online). 我通过将PNG转换为SVG(在线)而获得了成功。 The problem I had was while the image was meant to be 72x72px, the on-line converter had scaled it to something pretty big. 我遇到的问题是,当图像的尺寸为72x72px时,在线转换器将其缩放至相当大的尺寸。

This has actually worked in my favour as I need to use the circle in various sizes. 这实际上对我有利,因为我需要使用各种尺寸的圆。

So I used .transform() to scale it down and transform it to the size I need it to be. 因此,我使用.transform()将其缩小并转换为所需的大小。 It feels like a bit of a hack. 感觉有点像黑客。 Is there a better way? 有没有更好的办法? Or is this the best you can do? 还是这是您能做的最好的事情?

Here is my code: http://jsfiddle.net/9LHUE/ . 这是我的代码: http : //jsfiddle.net/9LHUE/

Thanks in advance. 提前致谢。

Using .transform() is just fine. 使用.transform()很好。 The whole idea of "Scalable Vector Graphics" is that they are, well, scalable. “可缩放矢量图形”的整个思想是,它们是可缩放的。 Since they are rendered on the page from coordinate-based definitions, they should look just as good at any size. 由于它们是根据基于坐标的定义显示在页面上的,因此无论大小如何,它们的外观都应相同。

What feels like a hack to me is importing this nicely geometric figure from a png, rather than working out the definitions in a more mathematical way. 对我来说,感觉像是骇客,是从png导入此精美的几何图形,而不是以更数学的方式得出定义。 I doubt you really need so monstrous a bezier curve for so simple a shape. 我怀疑您真的需要如此简单的形状这么巨大的贝塞尔曲线。

That said, I don't know what an "off-circle" is. 也就是说,我不知道什么是“离线”。 Maybe it's not simple at all. 也许这并不简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM