Created
January 18, 2018 22:09
-
-
Save robert-moore/4204529708a429e4ae563ce79385947a to your computer and use it in GitHub Desktop.
SVG Drop Shadow
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
export function addDropShadowDef(defsSelection, id, size, opacity) { | |
const filter = defsSelection.append("filter") | |
.attr("id", id) | |
.attr("height", "130%") | |
filter.append("feGaussianBlur") | |
.attr("in", "SourceAlpha") | |
.attr("stdDeviation", size * 1.5) // stdDeviation is how much to blur | |
filter.append("feOffset") | |
.attr("dx", size) | |
.attr("dy", size) | |
.attr("result", "offsetblur") | |
filter.append("feComponentTransfer") | |
.append("feFuncA") | |
.attr("type", "linear") | |
.attr("slope", opacity) // slope is the opacity of the shadow | |
const feMerge = filter.append("feMerge") | |
feMerge.append("feMergeNode") // this contains the offset blurred image | |
feMerge.append("feMergeNode") | |
.attr("in", "SourceGraphic") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment