grayscale in chrome via css

2019-02-15 10:48发布

Is there a way to make a grayscale image in chrome via css?

I have tried this but doesn't work on latest version of chrome

4条回答
Luminary・发光体
2楼-- · 2019-02-15 11:29

Not yet, but Chrome 18 will support css filters (released later this year). SVG filters is only supported by Firefox. You should be able to find a consistent canvas+javascript solution though.

EDIT: See Erik Dahlström's post for alternate solution.

查看更多
Root(大扎)
3楼-- · 2019-02-15 11:29

Here's an HTML5 solution. Supported by current versions of Chrome: http://webdesignerwall.com/demo/html5-grayscale/

查看更多
劳资没心,怎么记你
4楼-- · 2019-02-15 11:34

Another solution would be svg with a level of indirection.

Basically, <img src="wrapper.svg"/> where wrapper.svg applies an svg filter to the svg, and the svg has an image element pointing to your raster image. Works in Opera, Chrome, Firefox and probably IE10 (untested).

Here's a demo. You can pass in your own url if you encodeURIComponent it first. Note though that for passing in parameters to work it relies on scripting being enabled, so if you need to use it in <img> elements or in a css background image you'd need to generate the svg files on the server.

查看更多
Lonely孤独者°
5楼-- · 2019-02-15 11:46

support for native CSS filters in webkit has been added from the current version 19.0.1084.46

so -webkit-filter: grayscale(1) will work and which is better and easier approach than SVG for webkit...

查看更多
登录 后发表回答