Created
March 25, 2018 02:06
-
-
Save PavelLaptev/f3115c8393a9541f5c852e2a20528ac4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gradientSVG = (params) -> | |
# PARAMETERS # | |
name = params.name || "Add SVG layer" | |
startColor = params.startColor || "rgb(255,255,0)" | |
endColor = params.endColor || "rgb(255,0,0)" | |
startOffset = params.startOffset || 0 | |
endOffset = params.endOffset || 100 | |
angle = params.angle || 0 | |
# IMPLEMENT PARAMS # | |
svgns = "http://www.w3.org/2000/svg" | |
SVGel = document.querySelectorAll("[name=#{name.name}]")[0].parentNode | |
svgDefs = document.createElementNS(svgns, "defs") | |
svgDefs.innerHTML = '<linearGradient id="gradient-' + name.name + '"gradientTransform="rotate(' + angle + ')"><stop offset="' + startOffset + '%" style="stop-color:' + startColor + ';"/><stop offset="' + endOffset + '%" style="stop-color:' + endColor + '"/></linearGradient>' | |
SVGel.appendChild(svgDefs) | |
name.fill = "url(#gradient-" + name.name + ")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment