有什么方法可以反转父 div 中的每个颜色集,还是我只需要为它构建一个新的样式表?
谢谢!
最佳答案
在 http://jsfiddle.net/cZNRZ/ 进行处理.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.js'></script>
<style type='text/css'>
span {color:blue;}
#hello {color:red;}
</style>
<script type='text/javascript'>
//<![CDATA[
function invertColor (rgbString) {
var parts = rgbString.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
parts.splice(0, 1);
parts = $.map(parts,
function (item) {
return (255-parseInt(item, 10));
}
);
return 'rgb(' + parts.join(',') + ')';
}
function invertme () {
$('#hello').parent().find('*').each(function () {
var color = $(this).css('color');
$(this).css('color', invertColor(color));
});
}
$(function () {
$('#button').click(invertme);
});
//]]>
</script>
</head>
<body>
<div>
<span id="hello">Hello</span>
<span>World</span>
</div>
<input type="button" value="invert" id="button"/>
</body>
</html>
关于javascript - 有没有办法反转父 div 中的每个颜色集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6105328/