Created
March 21, 2023 12:55
-
-
Save skle/2a75ee934babfb9800c985bdb0e508f2 to your computer and use it in GitHub Desktop.
Convert SVG Polygon to CSS clip-path polygon
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
| const sPoints = '4.78,144.93 14.74,124.24 3.33,103.45 0.96,82.88 16.31,62.43 5.59,41.86 0.2,21.29 25.35,1.13 490.9,0.18 490.2,5.86 495.48,27.12 483.43,49.25 476.42,71.15 496,91.72 483.6,113.85 493.97,134.88 499.18,154.58 3.56,155.53' | |
| const iViewboxWidth = 500; | |
| const iViewboxHeight = 155; | |
| const aPoints = sPoints.split(' ').map(function(v) | |
| { | |
| v = v.split(','); | |
| v[0] = Math.round((v[0]/iViewboxWidth) * 10000)/100+'%'; | |
| v[1] = Math.round((v[1]/iViewboxHeight) * 10000)/100+'%'; | |
| return v.join(' '); | |
| }); | |
| const sCss = `clip-path: polygon(${aPoints.join(',')})`; |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 500 155" xml:space="preserve"> | |
| <polygon fill="black" points="4.78,144.93 14.74,124.24 3.33,103.45 0.96,82.88 16.31,62.43 5.59,41.86 0.2,21.29 25.35,1.13 490.9,0.18 490.2,5.86 495.48,27.12 483.43,49.25 476.42,71.15 496,91.72 483.6,113.85 493.97,134.88 499.18,154.58 3.56,155.53"/> | |
| </svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment