如何向 Raphael.js 对象添加阴影?
我想了解如何向 Raphael.js 对象/路径添加模糊边缘阴影。据我所知,图书馆不可能按原样进行,但有解决办法吗?
I would like to find out how to add blurry edged drop shadows to Raphael.js objects/paths. As far as I know it is not possible with the library as is but is there a work around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用
Element.glow([glow])
来获得阴影效果。 http://raphaeljs.com/reference.html#Element.glowYou can use the
Element.glow([glow])
to get a shadow effect. http://raphaeljs.com/reference.html#Element.glow根据 OP 的要求,在单独的答案中添加 Raphael.blur 的链接。
http://github.com/DmitryBaranovskiy/raphael/blob/master /plugins/raphael.blur.js
更新的代码示例:
请注意,在 Dmitry 的评论中,他提到没有 WebKit 支持。他使用
元素和 feGaussianBlur 滤镜效果。 WebKit 已经实现了 feGaussianBlur 效果,但是滤镜不稳定并且在 Safari 中被禁用(可能会在 Chrome 5 中工作 - 绝对应该在 Chrome 6 中工作)。Adding a link to Raphael.blur in a separate answer, per the OP's request.
http://github.com/DmitryBaranovskiy/raphael/blob/master/plugins/raphael.blur.js
Updated code sample:
Note that in Dmitry's comments he mentions that there is no WebKit support. He uses the
<filter>
element and the feGaussianBlur filter effect. 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).我编写了一个插件,通过对元素应用 SVG 过滤器来向元素添加阴影。
它基于模糊插件。
您可以在这里找到它:https://github.com/dahoo/raphael.dropshadow.js
I wrote a plugin that adds a drop shadow to an element by applying an SVG filter to it.
It's based on the blur plugin.
You can find it here: 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.
You can also adjust the opacity attribute if needed.
您可以使用发光来添加阴影。
.glow({ color: '#900', width:10, offsetx:5 }) // 随机示例...
查看 文档
You can use a glow to add shadows.
.glow({ color: '#900', width:10, offsetx:5 }) // random example...
check out the documentation