admin管理员组文章数量:1384760
I have an star icon. I want to use this icon in an unknown number of colors.
Sometimes I need a red star, sometimes a purple star.
I could dynamically create images on the server with a web service.
What I'm curious about, is there any way to control the color of this icon without explicitly creating an image for every color I may need ?
I have an star icon. I want to use this icon in an unknown number of colors.
Sometimes I need a red star, sometimes a purple star.
I could dynamically create images on the server with a web service.
What I'm curious about, is there any way to control the color of this icon without explicitly creating an image for every color I may need ?
Share Improve this question asked Apr 5, 2013 at 17:03 BentOnCodingBentOnCoding 28.2k14 gold badges66 silver badges93 bronze badges 2- 2 Perhaps you could make an icon with transparency and change the color of the background. – FishBasketGordo Commented Apr 5, 2013 at 17:05
- use a canvas object, or a transparent image and change the background colors. – Marc B Commented Apr 5, 2013 at 17:05
4 Answers
Reset to default 3You should use glyphicons or some other type of icon-based font: http://twitter.github./bootstrap/base-css.html#icons
Here's an example of icon-based fonts in action: http://css-tricks./examples/IconFont/
I can think of three ways to do this.
- Create a sprite sheet with all the different colors you need, and shift offsets to change colors. This is kinda cheating.
- Dynamically generate the image using Canvas (ugh!)
- Use SVG, which will respond to changes to the CSS similar to changing text display by changing the class on the DIV/SPAN
With SVG icons you can do whatever you want :)
Here's an example with the Raphael JS Library: http://raphaeljs./icons/
You could generate just 4 star images: 1 black, 1 red, 1 blue and 1 green (maybe 1 white too, if you have a non-white background). Then stack all of them and play with their opacity to obtain the color you want.
本文标签: javascriptIs there a way to dynamically change the color of an iconStack Overflow
版权声明:本文标题:javascript - Is there a way to dynamically change the color of an icon? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744503384a2609449.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论