-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.html
197 lines (169 loc) · 6.54 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="en">
<head>
<title>Clip-path converter</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<header class="page-header">
<h1>Convert SVG absolute clip-path to relative</h1>
</header>
<main class="main">
<section class="section">
<h2 class="visuallyhidden">Codes</h2>
<div class="container">
<header class="container__header">
<h3>
<label for="src-text">
Insert clip-path coordinates for <code>userSpaceOnUse</code>:
</label>
</h3>
</header>
<textarea
id="src-text"
placeholder="M 20,20 h 160 v 160 h -80 v -80 h -80 z"
spellcheck="false"
></textarea>
</div>
<div class="container">
<header class="container__header">
<h3>
<label for="result-text">
Take clip-path coordinates for <code>objectBoundingBox</code>:
</label>
</h3>
<label class="container__label">
<input
type="checkbox"
id="remove-offsets-control"
>
Remove offset
</label>
</header>
<textarea
id="result-text"
placeholder=""
spellcheck="false"></textarea>
</div>
</section>
<section class="section">
<h2 class="">Live demos</h2>
<div class="result"></div>
</section>
<section class="section">
<h2 class="">All together now</h2>
<div class="full-codes">
<div class="
full-codes__item"
>
<h3>
<label for="css-code">CSS</label>
</h3>
<textarea
id="css-code"
class="
full-codes__css-code"
></textarea>
<h3>
<label for="html-code">SVG + HTML</label>
</h3>
<textarea
id="html-code"
class="
full-codes__html-code"
></textarea>
</div>
<div class="
full-codes__result
full-codes__item"
>
<style>
.svg {
position: absolute;
width: 0;
height: 0;
}
.clipped {
width: 100%;
height: 350px;
background: turquoise url(https://source.unsplash.com/600x600?summer);
background-size: cover;
-webkit-clip-path: url(#my-clip-path);
clip-path: url(#my-clip-path);
}
</style>
<svg class="svg">
<clipPath id="my-clip-path" clipPathUnits="objectBoundingBox"><path d="M0.5,0, L1,1, H0"></path></clipPath>
</svg>
<div class="clipped"></div>
</div>
</div>
</section>
<section class="section">
<h2 class="">About</h2>
<p>The converter is just preparing SVG path to be used in CSS clip-path.</p>
<p>If we'll take a path from editor or ordinary SVG icon, it'll have absolute coordinates and <a href="https://codepen.io/yoksel/pen/QWWWRqv">will not be stretched</a>. There are some <a href="https://twitter.com/AlaricBaraou/status/1180958279570280448">funny</a> <a href="https://twitter.com/paullebeau/status/1181169153287155712">hacks</a> to solve this problem, but I think, it will be easier to translate coordinates from absolute to relative and just use path.</p>
<p>Read about clip-path:</p>
<ul>
<li>
<a href="https://developer.mozilla.org/ru/docs/Web/CSS/clip-path">Clip-path on MDN</a>
</li>
<li>
<a href="https://css-tricks.com/clipping-clipping-and-more-clipping/">Clipping, Clipping, and More Clipping!</a>
</li>
<li>
<a href="https://css-tricks.com/animating-with-clip-path/">Animating with Clip-Path</a>
</li>
<li>
<a href="https://css-tricks.com/tag/clip-path/">and more...</a>
</li>
</ul>
</section>
</main>
<footer class="footer">
<a href="https://github.com/yoksel/relative-clip-path/">Project on GitHub</a>
<a href="https://twitter.com/yoksel_en">@yoksel_en</a>
</footer>
</div>
<template id="demos-tmpl">
<div class="demos">
<div class="demos__svg-container">
<svg>
<clipPath id="clip-path-before" clipPathUnits="userSpaceOnUse"></clipPath>
<clipPath id="clip-path-after" clipPathUnits="objectBoundingBox"></clipPath>
</svg>
</div>
<div class="demos__item">
<h3>Svg with initial path</h3>
<div class="src-container">
<svg>
</svg>
</div>
</div>
<div class="demos__item">
<h3>Clip-path with initial path</h3>
<div class="demo">
<div class="demo__target demo__target--before"></div>
</div>
</div>
<div class="demos__item">
<h3>Clip-path with relative path</h3>
<div class="demo">
<div class="demo__target demo__target--after"></div>
</div>
</div>
</div>
</template>
<script src="script.js"></script>
<script>
const pathConverter = new PathConverter({
srcTextElem: document.getElementById('src-text'),
resultTextElem: document.getElementById('result-text'),
demoTargetElem: document.querySelector('.result'),
addExamples: true
});
</script>
<!-- Yandex.Metrika counter --> <script type="text/javascript" > (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"); ym(55838086, "init", { clickmap:true, trackLinks:true, accurateTrackBounce:true }); </script> <noscript><div><img src="https://mc.yandex.ru/watch/55838086" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- /Yandex.Metrika counter -->
</body>
</html>