使用 jQuery 更改平面图像的颜色
我有一个平坦的白色圆形图像(如非常平坦的 #ffffff
图像)。有没有办法可以在 HTML 页面的上下文中更改它的颜色(假设是 PNG
,所以我们正在使用 RGBA 栅格)?
我的环境使用 jQuery,因此我倾向于以 jQuery 的思维方式进行思考,但如果有其他方法使这成为可能,我也想听听。
我不太熟悉 Canvas 的功能,但也许它可以做这样的事情。然而,就浏览器支持而言,如果该解决方案能够与 IE6 接触,我将非常感激(是的,我知道它已经死了,但请耐心等待)。
I have a flat white circular image (as in a seriously flat #ffffff
image). Is there a way I can change it's color in the context of an HTML page (let's assume PNG
, so we're working with an RGBA raster)?
My environment uses jQuery, so I'm inclined to think within the jQuery mindset, but if something else makes this possible, I'd like to hear about it as well.
I'm not well versed with the capabilities of Canvas so much, but maybe that can do something like this. With respect to browser support however, I'd really appreciate it if the solution can touch base with IE6 (yeah, I know it's dead, but bear with me on this one).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否考虑过使用画布并在图像下方绘制圆圈,然后更改其颜色?遵循其他答案,使图像透明,然后将其分层在画布上。
http://www.html5canvastutorials.com/tutorials/html5-canvas-circles/
Have you thought about using a canvas and drawing the circle below the image, then change it's color? Following on from the other answer and make the image transparent and then layer it about the canvas.
http://www.html5canvastutorials.com/tutorials/html5-canvas-circles/
您可以在支持边框半径的浏览器中“模拟”圆形。尝试;
然后相应地更改背景颜色。
是的,我知道,不支持 IE6,但也许你可以依靠上面提到的透明图像效果
You can 'emulate' a circle in browsers that support border radius. Try;
Then change background-color accordingly.
Yeah, I know, no IE6 support but maybe you could fall back on the transparent image effect as mentioned above
最终还是使用了画布。废弃图像想法,然后使用画布绘制圆圈(和 jCanvas 使其与jQuery 环境)。基本上将
标签本身视为
等效项,并且可能根据需要动态创建它们。
为了让它与 IE9 之前的浏览器(不支持 HTML5)一起工作,有一个漂亮的库,名为 ExplorerCanvas 为 IE9 之前的浏览器带来了画布功能(它至少可以与 IE9 上的 IE7 怪异模式配合使用)。
如果您要在 ExplorerCanvas 上执行画布动画,预计性能会下降,但由于这只是 2D 静态,因此应该不会有太大问题。
还有处理动态
的问题元素与 ExplorerCanvas,但这应该很容易修复。
Ended up utilizing canvas after all. Scrapping the image idea, and just going with drawing the circles using canvas (and jCanvas to make it modular with the jQuery environ). Basically going with treating the
<canvas>
tag itself as the<img>
equivalent, and maybe work with dynamically creating them as needed.To get it working with pre-IE9 browsers (where HTML5 support is non-existent), there's a nifty lib out there called ExplorerCanvas which brings the canvas functionality to pre-IE9 browsers (it certainly works with the IE7 quirks mode on IE9 at least).
There's expectedly a performance drop if you're going to be performing canvas animations on ExplorerCanvas, but since this is all just 2D static, it shouldn't be too much of a problem.
There's also the matter of dealing with dynamic
<canvas>
elements with ExplorerCanvas, but that should be easily remedied.