【发布时间】:2011-08-16 16:40:23
【问题描述】:
我不确定这是否可行,但我正在尝试获取 $css_color 的值并将其设置为 div 中的十六进制值。还有 $x 和 $y 值。
本质上,我正在尝试从图像中获取 $x$y 信息和十六进制代码值,并将其与我在 formatted_colors.js 中的颜色值数组进行匹配,然后将“图像”重建为 div背景颜色作为测试。
我的 formatted_colors.js 数组示例var colors = []; colors["000000"] = "black"; colors["100000"] = "black";
这是一个sn-p:
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script src="formatted_colors.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
//iterate through pixels and match rounded color to array in formatted_colors.js
<div class="rounded_color" hex="<?php $css_color ?>" xy="<?php $x.$y ?>"</div>
<div id="<?php $x.$y ?>"></div>
$(document).ready(function() {
$(".rounded_color").each(function(){
var google_color = getColor($(this).attr("hex"));
$('#'+$(this).attr("id")).html(google_color);
$('#'+$(this).attr("id")).css('background-color:', google_color);
})
// get name of color function from formatted_colors.js
function getColor(target_color){
if (colors[target_color] == undefined) { // not found
return "no match";
} else {
return colors[target_color];
}
} // end getColor function
)} // end ready function
</script>
这是我的完整代码:http://pastebin.com/A4tMsn2C
【问题讨论】:
标签: php javascript jquery html syntax