Can the opacity / translucence of an SVG group be adjusted together?

I have an SVG "g" object that has several components. I'd like to render the whole thing partly transparent (e.g. alpha = 0.5) I'd also like to to be darker if possible. I know individual fill colors can be adjusted, but how about all of them together, possibly in some parameters to the "g" (grouping) structure.

Solved

Changing the opacity of the (either by the opacity="..." attribute, or the opacity CSS rule) will cause the contents of the group to first be composited and then the result to be lowered in opacity. Note that this is distinctly different from lowering the opacity on all the elements inside the group (which you can also do via CSS):

Demo: http://jsfiddle.net/HZr7v/12/

enter image description here

Uses this SVG:


    
      
    
     
        
    
    
        
    
    
        
    
    
        
    

…with this CSS:

circle { fill:red }
rect { fill:blue }

#g2 * { opacity:0.5 }         /* Change the opacity of each shape    */
#g3   { opacity:0.5 }         /* Change the opacity of the group     */
#g4   { filter:url(#Darker) } /* Darkens and drops opacity for group */

Note in particular the difference in appearance where the circle and square overlap.

The feColorMatrix filter looks daunting. All it does is set the RGB values to each be 30% of the original RGB (i.e. darker), and the alpha to be 80% of the original alpha. Change the values as you see fit.


Oh, and if you want to desaturate also you can throw this into the filter (before or after the darken step):






You could set opacity on the itself and that would work. If you want it darker you'll need to apply a filter to the something along these lines perhaps

    
      
      
    

Comments

Popular posts from this blog

When i am using UIImagePNGRepresentation or UIImageJPEGRepresentation for converting UIImage into NSdata, the image size is too much increased

Frontend live-preview in Wordpress

uable to assign TempData value to a variable in a View in mvc 4