HTML5 中是否可以实现类似 Photoshop 的混合模式?
我想在我的网页上放置一个红色矩形
元素,这样它不仅看起来是透明的,而且就像在 Photoshop 的乘法模式中混合的一样。
将具有 position:fixed
,因此其下方的内容会快速更改。任何 HTML5 / CSS3 / canvas / SVG 技巧都可以实现吗?
I want to put a red rectangular <div>
element over my webpage so that it would look not only transparent, but also like blended in Photoshop’s Multiply mode.
The <div>
would have position: fixed
, so the content below it would change quickly.
Is that possible with any HTML5 / CSS3 / canvas / SVG trick?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我创建了一个单独的、轻量级的开源库,用于从一个 HTML Canvas 上下文到另一个上下文执行 Photoshop 风格的混合模式:
请参阅 README 了解更多信息,包括当前支持的混合模式。
您可以使用它来执行从一个画布到另一个画布的乘法,但不能在标准 HTML 元素上执行。
I have created a separate, lightweight, open-source library for perform Photoshop-style blend modes from one HTML Canvas context to another: context-blender. Here's the sample usage:
See the README for more information, including the currently-supported blend modes.
You could use this to perform multiply from one canvas to another, but not over standard HTML elements.
不(不是原生的),但很快就会推出:http://blogs .adobe.com/webplatform/2012/04/04/bringing-blending-to-the-web/
No (not natively) but it's coming soon: http://blogs.adobe.com/webplatform/2012/04/04/bringing-blending-to-the-web/
您还可以查看此演示:http://media.chikuyonok.ru/canvas-blending/ 了解如何用画布来做到这一点。
检查混合模式公式的来源以及如何应用它们(公式比 pixastic 或 context-blender 中的公式更具可读性)。
You can also look at this demo: http://media.chikuyonok.ru/canvas-blending/ to see how to do this with canvas.
Check the source for blending modes' formulae and how to apply them (formulae are much more readable than in pixastic or context-blender).
这不是 HTML5,但它是我能找到的最接近您所要求的内容的。
Javascript 混合模式 (OpenGL)。
我不认为像 Photoshop 这样的“混合模式”可以仅用纯 HTML 来模拟,除非该语言朝另一个方向急剧转变。但很高兴看到一些更简单的方法来做到这一点。
This isn't HTML5, but it's as close as I can find for what you're asking.
Javascript blending modes (OpenGL).
I don't think "blend modes" like Photoshop could be emulated with just pure HTML, unless the language took a sharp turn in another direction. But it would be great to see some easier way of doing this.
我也对此非常感兴趣。我为视觉设计师编写的许多布局都可以使用它。除了本线程中的其他帖子之外,还有一种方法可以做到这一点,目前仅在 Firefox 4 中,无需使用 OpenGL 或 Canvas。这是通过使用 SVG 过滤器实现的。显然,Webkit 和 Chrome 的睡衣上也有这个功能,但我还没有看到任何功能。
以下是一些演示和说明:(
恕我直言,任何接近混合模式的东西现在都很难实现。很难找到有关 feConvolveMatrix、feSpecularLighting 或 feColorMatrix 的任何参考资料,而且这些示例对我来说根本无法理解。他们可以工作,但我不知道如何。
我希望像 EffectGames 建议这样的东西:
这会更好方法。也许那里的一些精通数学的忍者可以让我们有能力做到这一点。
编辑:有一个更简单的 SVG 规范可以精确地执行混合模式。但我测试的浏览器都没有这个功能(FF4、IE9、Opera11、Webkit Nightly): http://dev.w3.org/SVG/modules/compositing/master/SVGCompositingPrimer.html - 但我也不知道这是否可以在 HTML-DOM 元素中使用。
I am also very interested in doing that. Many layouts that I coded for visual designers could have used that. Aside from the other posts in this thread, there is a way to do this, currently only in Firefox 4, without using OpenGl or Canvas. It's trough the use of SVG filters. Aparrently it's on nighties from Webkit and Chrome also, but I couldn't see anything working yet.
Here are some demos and explanations:
IMHO something anyware close to blend modes are too much hard to achieve right now. It's very hard to find any references on
feConvolveMatrix
,feSpecularLighting
, orfeColorMatrix
, and the examples are just impossible to figure out for me. They could work but I don't know how.I wish something like EffectGames suggested:
This would be a way better approach. Maybe some ninja there skiled in mathematics could make us a lib to do that.
EDIT: There is an easier SVG spec to do exactly blend modes. But no browser that I tested have this working (FF4, IE9, Opera11, Webkit Nightly): http://dev.w3.org/SVG/modules/compositing/master/SVGCompositingPrimer.html - But I also don't know if this will be possible to use in HTML-DOM elements.
它已登陆 Chrome Canary,因此应该很快就会发布。 http: //blogs.adobe.com/webplatform/2013/04/23/all-blend-modes-for-css-fragment-shaders-have-landed/
It's landed in Chrome Canary so should reach release soon. http://blogs.adobe.com/webplatform/2013/04/23/all-blend-modes-for-css-fragment-shaders-have-landed/
这是我见过的最接近的,并且是的,所有资源都必须在画布中。请注意,Internet Explorer 在版本 9 中开始支持画布,该版本尚未发布,因此如果您必须支持 IE<9,则必须使用解决方法。
This is the closest I have seen, and yes, all assets have to be in the canvas. Note that Internet Explorer starts supporting canvas in version 9 which is not out yet, so if you have to support IE<9 you'll have to use a workaround.
您已经可以通过简单的 CSS(无 Canvas)来使用它。示例:
Internet Explorer 可能不支持它,但其他浏览器支持。
https://developer.mozilla.org/en-US /docs/Web/CSS/mix-blend-mode
You can already use it with just simple CSS (no Canvas). Example:
Internet Explorer may not support it, but the other browsers do.
https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
根据所涉及的图像和您想要的确切效果,您也许可以对图像和 CSS 渐变进行一些创造性的分层,以达到所需的效果:
http://jonathonhill.net/2012-04-23/blending-css-gradients-like-photoshop/
Depending on the images involved and the exact effect you are after, you might be able to do some creative layering of images and CSS gradients to achieve the desired affect:
http://jonathonhill.net/2012-04-23/blending-css-gradients-like-photoshop/
我已经使用 http://canvasquery.com/ 中的画布实现了 gimp/photoshop 中已知的最流行的混合模式,但是它是不适合关系。
随着画布中引入本机混合模式
https: //dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blendingseparable
I have implemented most popular blend modes known from gimp/photoshop using canvas in http://canvasquery.com/ however it is not suitable for relatime.
This will change with introduction of native blend modes in canvas
https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blendingseparable