简体   繁体   English

如何为Raphael.js对象添加阴影?

[英]How can one add drop shadows to Raphael.js objects?

I would like to find out how to add blurry edged drop shadows to Raphael.js objects/paths. 我想了解如何向Raphael.js对象/路径添加模糊的边缘阴影。 As far as I know it is not possible with the library as is but is there a work around? 据我所知,使用库是不可能的,但是可以解决吗?

You can use the Element.glow([glow]) to get a shadow effect. 您可以使用Element.glow([glow])获得阴影效果。 http://raphaeljs.com/reference.html#Element.glow http://raphaeljs.com/reference.html#Element.glow

Adding a link to Raphael.blur in a separate answer, per the OP's request. 根据OP的请求,在单独的答案中添加指向Raphael.blur的链接。

http://github.com/DmitryBaranovskiy/raphael/blob/master/plugins/raphael.blur.js http://github.com/DmitryBaranovskiy/raphael/blob/master/plugins/raphael.blur.js

Updated code sample: 更新的代码示例:

var shadow = canvas.path(p);
shadow.attr({stroke: "none", fill: "#555", translation: "4,4"});
shadow.blur(4);
var shape = canvas.path(p);

Note that in Dmitry's comments he mentions that there is no WebKit support. 请注意,在Dmitry的评论中,他提到没有WebKit支持。 He uses the <filter> element and the feGaussianBlur filter effect. 他使用<filter>元素和feGaussianBlur滤镜效果。 WebKit has implemented the feGaussianBlur effect, but filters are unstable and are disabled in Safari (it may work in Chrome 5 - should definitely work in Chrome 6). WebKit已经实现了feGaussianBlur效果,但是过滤器不稳定并且在Safari中被禁用(它可能在Chrome 5中可用-绝对应该在Chrome 6中起作用)。

I wrote a plugin that adds a drop shadow to an element by applying an SVG filter to it. 我编写了一个插件,该插件通过对元素应用SVG过滤器来向其添加阴影。 It's based on the blur plugin. 它基于模糊插件。

You can find it here: https://github.com/dahoo/raphael.dropshadow.js 您可以在这里找到它: https : //github.com/dahoo/raphael.dropshadow.js

The easiest way to do it is simply to draw the object with a shadow-colored fill, offset by a few pixels, and then draw the actual object on top. 最简单的方法是简单地用阴影色填充对象(偏移几个像素),然后在顶部绘制实际对象。

var shadow = canvas.path(p);
shadow.attr({stroke: "none", fill: "#555", translation: "4,4"});
var shape = canvas.path(p);

You can also adjust the opacity attribute if needed. 如果需要,您还可以调整opacity属性。

You can use a glow to add shadows. 您可以使用光晕添加阴影。

.glow({ color: '#900', width:10, offsetx:5 }) // random example...

check out the documentation 查看文档

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

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