[英]changing colour of a background image with js on the fly
我一直在寻找使用javascript更改图像颜色的方法,但问题是我需要更改图像的背景颜色-即向其添加色彩
因此,我在这里阅读了很多文章,并且当html中包含img(即src)时似乎可行,但我找不到背景图片的任何解决方案
所以我的CSS可能有这个
.productBenefits ul li {
background: url("tick.png") no-repeat scroll 0 4px transparent;
}
取决于网址,例如我有不同的颜色,我需要使用提供的十六进制为背景图像上色-例如#ff0000
有人可以帮忙吗?
您是否正在寻找这样的东西: http : //jsfiddle.net/AyyU6/1/
HTML:
Hover on the links, and see the result
<br>
<a href='#' data-color='#fff000'>Color 1</a>
<a href='#' data-color='#fffaaa'>Color 2</a>
<a href='#' data-color='#333000'>Color 3</a>
<a href='#' data-color='#123000'>Color 4</a>
<a href='#' data-color='#fff555'>Color 5</a>
<div style="width: 100px; height:100px;">
</div>
Javascript:
$('a').mouseenter(function(){
// Getting color information from the links data-color attr, of course it can be anything you define
var color = $(this).attr('data-color');
$('div').css('background-color',color);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.