diff options
author | wout <wout@impinc.co.uk> | 2012-12-31 12:21:45 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-31 12:21:45 +0100 |
commit | 9f622f7b160fb977a4354eb0f775d4b53a2f7443 (patch) | |
tree | 120ab0acc0e073b89a9f68594c36d8a1501bdc20 /src/mask.js | |
parent | 7d3e4c43a64cdb9ce19b71d8dc1783c0bc031d91 (diff) | |
download | svg.js-9f622f7b160fb977a4354eb0f775d4b53a2f7443.tar.gz svg.js-9f622f7b160fb977a4354eb0f775d4b53a2f7443.zip |
Added mask.js
Diffstat (limited to 'src/mask.js')
-rw-r--r-- | src/mask.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/mask.js b/src/mask.js new file mode 100644 index 0000000..a9b457e --- /dev/null +++ b/src/mask.js @@ -0,0 +1,42 @@ + +SVG.Mask = function Mask() { + this.constructor.call(this, SVG.create('mask')); + + // set unique id + this.id = 'svgjs_' + (SVG.did++); + this.attr('id', this.id); +}; + +// inherit from SVG.Element +SVG.Mask.prototype = new SVG.Element(); + +// include the container object +SVG.extend(SVG.Mask, SVG.Container); + +// add clipping functionality to element +SVG.extend(SVG.Element, { + + // mask element using another element + mask: function(b) { + var m = this.parent.defs().mask(); + b(m); + + return this.maskTo(m); + }, + + // distribute mask to svg element + maskTo: function(m) { + return this.attr('mask', 'url(#' + m.id + ')'); + } + +}); + +// add def-specific functions +SVG.extend(SVG.Defs, { + + // create clippath + mask: function() { + return this.put(new SVG.Mask()); + } + +});
\ No newline at end of file |