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


i have svg "g" object has several components. i'd render whole thing partly transparent (e.g. alpha = 0.5) i'd to darker if possible. know individual fill colors can adjusted, how of them together, possibly in parameters "g" (grouping) structure.

changing opacity of <g> (either opacity="..." attribute, or opacity css rule) cause contents of group first composited , result lowered in opacity. note distinctly different lowering opacity on elements inside group (which can via css):

demo: http://jsfiddle.net/hzr7v/12/

enter image description here

uses svg:

<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400">     <defs><filter id="darker">       <fecolormatrix type="matrix" values="        0.3  0   0   0   0         0  0.3  0   0   0         0   0  0.3  0   0         0   0   0  0.8  0"/>     </filter></defs>     <g id="g1" transform="translate(60,60)"> <!-- top left -->         <circle r="40" /><rect width="80" height="60" />     </g>     <g id="g2" transform="translate(220,60)"><!-- top right -->         <circle r="40" /><rect width="80" height="60" />     </g>     <g id="g3" transform="translate(60,200)"><!-- bottom left -->         <circle r="40" /><rect width="80" height="60" />     </g>     <g id="g4" transform="translate(220,200)"><!-- bottom right -->         <circle r="40" /><rect width="80" height="60" />     </g> </svg> 

…with css:

circle { fill:red } rect { fill:blue }  #g2 * { opacity:0.5 }         /* change opacity of each shape    */ #g3   { opacity:0.5 }         /* change opacity of group     */ #g4   { filter:url(#darker) } /* darkens , drops opacity group */ 

note in particular difference in appearance circle , square overlap.

the fecolormatrix filter looks daunting. set rgb values each 30% of original rgb (i.e. darker), , alpha 80% of original alpha. change values see fit.


oh, , if want desaturate can throw filter (before or after darken step):

<fecolormatrix type="saturate" values="0.5"/> <!-- values="0"  drop color, leaving grayscale --> <!-- values="1"  leave current saturation color     --> <!-- values="99" super-saturate colors              --> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -