English 中文(简体)
根据HxColor以前投入的内容自动更新对黑暗的HxColor的投入
原标题:Automatically update input to darker HexColor depending on what HexColor was entered in previous input

在这方面,我希望最终产品能够做些什么。 Saye 我有两个投入:

<form id="builder"/>
<input type="text" name="background_color" />
<input type="text" name="border_color" />
</form>

请说用户对《海尔彩色编码》在“背地-color”投入中的使用投入:#FF8CA9。 (图色)。 我想在“边界-col”投入中自动添加这种彩色海克斯法的黑暗语句:#D63E64(dark pink Fair)。

So is it possible to 1) Find darker tone of color that was entered in input "background_color" and generate Hex color code of it and 2) automatically place it in input "border_color" without page refresh?

I m not sure how to explain this in other way, I know it might sound confusing, but if you don t understand some parts please ask me.

<Additional info: 如果需要使用某种javascript,则更可取的办法。

最佳回答

I digged up an old piece of code which does exactly what you want. It might need some tuning. Run it like this:

add_to_color( #996600 , 10);

每一行将加10。 这将使彩色灯光亮。 使其更加黑暗——10。

function add_to_color(hex, addDec)                                                                                                                        
{                                                                                                                                                         
    hex = hex.replace( # ,   );                                                                                                                           
    rDec = Hex2Dec(hex.substr(0,2));                                                                                                                      
    gDec = Hex2Dec(hex.substr(2,2));                                                                                                                      
    bDec = Hex2Dec(hex.substr(4,2));                                                                                                                      

    if( rDec < -addDec || gDec < -addDec || bDec < -addDec )                                                                                              
    {                                                                                                                                                     
        return  # +hex;                                                                                                                                   
    }                                                                                                                                                     

    rDec = rDec + addDec;                                                                                                                                 
    gDec = gDec + addDec;                                                                                                                                 
    bDec = bDec + addDec;                                                                                                                                 

    hex = "#"+ Dec2Hex(rDec)+Dec2Hex(gDec)+Dec2Hex(bDec);                                                                                                 

    return hex;                                                                                                                                           
}

function Hex2Dec(HexVal)                                                                                                                                  
{                                                                                                                                                         
    HexVal=HexVal.toUpperCase();                                                                                                                          
    var DecVal=0;                                                                                                                                         
    var HV1=HexVal.substring(0,1);                                                                                                                        
    DecVal=(HexChars.indexOf(HV1)*16);                                                                                                                    
    HV1=HexVal.substring(1);                                                                                                                              
    DecVal+=HexChars.indexOf(HV1);                                                                                                                        
    return DecVal;                                                                                                                                        
}                                                                                                                                                         

// Created by T.N.W.Hynes - (c) 2002 PalandorZone.com ... Use it freely but leave this line intact                                                        
// Conversion function for Decimal to Hexadecimal - 255 max                                                                                               
function Dec2Hex(DecVal)                                                                                                                                  
{                                                                                                                                                         
    DecVal=parseInt(DecVal);                                                                                                                              
    if (DecVal > 255 || DecVal < 0)                                                                                                                       
    {                                                                                                                                                     
        DecVal=255;                                                                                                                                       
    }                                                                                                                                                     
    var Dig1 = DecVal % 16;                                                                                                                               
    var Dig2 = (DecVal-Dig1) / 16;                                                                                                                        
    var HexVal = HexChars.charAt(Dig2)+HexChars.charAt(Dig1);                                                                                             
    return HexVal;                                                                                                                                        
}
问题回答

你可以通过简单地把其罗姆社群的价值观乘以某种价值来获得更光明或更黑暗的颜色(或改写为HSV和修改V)。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签