Skip to content

Instantly share code, notes, and snippets.

@skle
Created March 21, 2023 12:55
Show Gist options
  • Select an option

  • Save skle/2a75ee934babfb9800c985bdb0e508f2 to your computer and use it in GitHub Desktop.

Select an option

Save skle/2a75ee934babfb9800c985bdb0e508f2 to your computer and use it in GitHub Desktop.
Convert SVG Polygon to CSS clip-path polygon
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(',')})`;
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment