Last active
November 25, 2020 18:03
-
-
Save rickbutterfield/96427c4d1f36d659397dc6a1b8557010 to your computer and use it in GitHub Desktop.
Polyfill getTotalLength support for SVG circles on iOS
This file contains hidden or 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
/** | |
* Polyfill SVG path support for iOS | |
*/ | |
SVGCircleElement.prototype.getTotalLength = function() { | |
let width = this.parentNode.clientWidth, // Get the parent node width (trying to get the current node width returns 0) | |
radius = width / 2, // Get the radius by dividing by 2 | |
length = 2 * Math.PI * radius; // Get the circumference from 2πr | |
// Return the calculated value | |
return length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment