11/01/2017 Development / css

With Sass

@mixin background-opacity($color, $opacity: 0.3) {
    background: $color; /* The Fallback */
    background: rgba($color, $opacity);
}

$colorTim : #00CC66;
$colorClaro: #B71C1C;
$colorOi : #0D47A1;
$colorVIVO : #FF9900;
$colorNextel : #CC00FF;
$colorCTBC : #00F2FF;
$colorSercontel : #000;

.leaflet-layer.baseRasterLayer.TIM img {
  @include background-opacity($colorTim, 0.2);
}

With Javascript

window.hexToRgbA = function(hex, opacity){
    var c;
    if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
        c= hex.substring(1).split('');
        if(c.length== 3){
            c= [c[0], c[0], c[1], c[1], c[2], c[2]];
        }
        c= '0x'+c.join('');
        return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255, opacity].join(',')+')';
    }
    throw new Error('Bad Hex');
};