Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Javascript color contrast finder

I am trying to create a javascript color contrast finder

function gamma_correction(r,g,b) {
    r=calc(r)
    g=calc(g)
    b=calc(b)
    r*=0.2126 
    g*=0.7152
    b*=0.0722 
    
    return r+g+b
}

function hexToRgb(hex) {
    result = /^#?(\[a-f\\d\]{2})(\[a-f\\d\]{2})(\[a-f\\d\]{2})$/i.exec(hex)
    return result ? {
        r:parseInt(result\[1\],16),
        g:parseInt(result\[2\],16),
        b:parseInt(result\[3\],16)
    } : null;
}

function calc(c) {
    let t = 0.03938;
    c/=255;
    return (c < t)? c /= 12.92: c = (((c + .055) / 1.055) ^ 2.4);
}

let x=document.getElementById('colorpicker')
x.addEventListener('change',()=\>{
    var {r,g,b} =hexToRgb(x.value)
    return document.getElementById('L1').innerText=gamma_correction(this.r,this.g,this.b)        
});

let y =document.getElementById('colorpicker2')
y.addEventListener('change',()=\>{
    var {r,g,b} =hexToRgb(y.value)
    return document.getElementById('L2').innerText=gamma_correction(this.r,this.g,this.b)   
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!