OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <style> |
| 3 .group { |
| 4 width: 400px; |
| 5 } |
| 6 </style> |
| 7 <body></body> |
| 8 <script> |
| 9 function createSvgElement(name, attributes) { |
| 10 var element = document.createElementNS('http://www.w3.org/2000/svg', name); |
| 11 for (var attrName in attributes) |
| 12 element.setAttribute(attrName, attributes[attrName]); |
| 13 return element; |
| 14 } |
| 15 |
| 16 const blendModes = [ |
| 17 "normal", |
| 18 "multiply", |
| 19 "screen", |
| 20 "darken", |
| 21 "lighten", |
| 22 "overlay", |
| 23 "color-dodge", |
| 24 "color-burn", |
| 25 "hard-light", |
| 26 "soft-light", |
| 27 "difference", |
| 28 "exclusion", |
| 29 "hue", |
| 30 "saturation", |
| 31 "color", |
| 32 "luminosity" |
| 33 ]; |
| 34 |
| 35 [ |
| 36 {a: 'rgb(255,0,0)', b: 'rgb(0,255,0)' }, |
| 37 {a: 'rgb(51,64,204)', b: 'rgb(153,192,102)' }, |
| 38 {a: 'rgba(51,64,204,0.5)', b: 'rgba(153,192,102,0.5)' }, |
| 39 ].forEach(function(colors) { |
| 40 var group = document.createElement('div'); |
| 41 group.className = 'group'; |
| 42 document.body.appendChild(group); |
| 43 |
| 44 blendModes.forEach(function(mode, i) { |
| 45 var filterId = 'f_' + mode; |
| 46 var filter = createSvgElement('filter', { id: filterId, x: 0, y: 0, width: 1
, height: 1 }); |
| 47 filter.appendChild(createSvgElement('feFlood', { result: 'a', 'flood-color':
colors.a })); |
| 48 filter.appendChild(createSvgElement('feFlood', { result: 'b', 'flood-color':
colors.b })); |
| 49 filter.appendChild(createSvgElement('feBlend', { in: 'a', in2: 'b', mode: mo
de })); |
| 50 var svgRoot = createSvgElement('svg', { width: '50', height: '50' }); |
| 51 var rect = createSvgElement('rect', { width: 50, height: 50, filter: 'url(#'
+ filterId + ')' }); |
| 52 svgRoot.appendChild(filter); |
| 53 svgRoot.appendChild(rect); |
| 54 group.appendChild(svgRoot); |
| 55 }); |
| 56 }); |
| 57 </script> |
OLD | NEW |