-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
112 lines (102 loc) · 5.04 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Image Comparison</title>
<style>
@layer base {
:where( :not( iframe, canvas, img, svg, video ):not( svg *, symbol * ) ) {
all: unset;
display: revert;
line-height: var( --font-line );
}
*, *::before, *::after {
box-sizing: border-box;
}
html {
height: 100%;
--font-default: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
--font-line: calc( 1em + .35rem );
--wrapper: 60rem;
--wrapper-offset: .5fr;
@media ( min-width: 40rem ) {
--wrapper-offset: 4rem;
}
--outline-size: max( 2px, .08em );
--outline-style: solid;
--outline-color: rebeccapurple;
}
body {
padding-block: 3rem;
font: 1em/var( --font-line ) var( --font-default );
color: #222;
background: #fff;
-webkit-font-smoothing: antialiased;
text-decoration-thickness: from-font;
}
}
@layer wrap {
.wrapping {
display: grid;
grid-template-columns:
[full-start]
minmax(1em, 1fr)
[mid-start]
minmax(0, var( --wrapper-offset ))
[main-start]
minmax(0, var( --wrapper ))
[main-end]
minmax(0, var( --wrapper-offset ))
[mid-end]
minmax(1em, 1fr)
[full-end];
align-content: start;
}
.wrapping > * {
grid-column: main;
}
.wrapping > * + * {
margin-top: 2rem;
}
}
figcaption {
margin-top: 1ex;
font-size: .9em;
}
.imgcompare:focus-within .range:focus-visible {
outline: var( --outline-size ) var( --outline-style ) var( --outline-color );
outline-offset: var( --outline-offset, var( --outline-size ) );
}
.otherstyle {
--o-imgcompare-thumbBackground: #007;
--o-imgcompare-thumbBackgroundFocus: #bada55;
--o-imgcompare-thumbWidth: min( 8px, .4em )
}
</style>
<link rel="stylesheet" href="image-comparison.css">
</head>
<body>
<main class="wrapping">
<figure>
<image-comparison class="imgcompare">
<img class="before" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTIwIiBoZWlnaHQ9IjEwODAiIHZpZXdCb3g9IjAgMCAxOTIwIDEwODAiPgogICAgPGRlZnM+CiAgICAgICAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiB4MT0iLjEiIHgyPSIuNyIgeTE9IjAiIHkyPSIuOCI+CiAgICAgICAgICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiNGQkFCN0UiLz4KICAgICAgICAgICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjRERENkYzIi8+CiAgICAgICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDwvZGVmcz4KICAgIDxyZWN0IGZpbGw9InVybCgjZ3JhZCkiIHdpZHRoPSIxOTIwIiBoZWlnaHQ9IjEwODAiLz4KICAgIDx0ZXh0IGZpbGw9InJnYmEoMCwwLDAsMC41KSIgZm9udC1mYW1pbHk9InNhbnMtc2VyaWYiIGZvbnQtc2l6ZT0iMzAiIGR5PSIxMC41IiBmb250LXdlaWdodD0iYm9sZCIgeD0iNTAlIiB5PSI1MCUiIHRleHQtYW5jaG9yPSJtaWRkbGUiPkxlZnQgSW1hZ2U8L3RleHQ+Cjwvc3ZnPg==" alt="An image with a gradient background and 'Left Image' written on it" />
<img class="after" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTIwIiBoZWlnaHQ9IjEwODAiIHZpZXdCb3g9IjAgMCAxOTIwIDEwODAiPgogICAgPGRlZnM+CiAgICAgICAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiB4MT0iLjEiIHgyPSIuNyIgeTE9IjAiIHkyPSIuOCI+CiAgICAgICAgICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiM4RUM1RkMiLz4KICAgICAgICAgICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjRkRCQjJEIi8+CiAgICAgICAgPC9saW5lYXJHcmFkaWVudD4KICAgIDwvZGVmcz4KICAgIDxyZWN0IGZpbGw9InVybCgjZ3JhZCkiIHdpZHRoPSIxOTIwIiBoZWlnaHQ9IjEwODAiLz4KICAgIDx0ZXh0IGZpbGw9InJnYmEoMCwwLDAsMC41KSIgZm9udC1mYW1pbHk9InNhbnMtc2VyaWYiIGZvbnQtc2l6ZT0iMzAiIGR5PSIxMC41IiBmb250LXdlaWdodD0iYm9sZCIgeD0iNTAlIiB5PSI1MCUiIHRleHQtYW5jaG9yPSJtaWRkbGUiPlJpZ2h0IEltYWdlPC90ZXh0Pgo8L3N2Zz4=" alt="An image with a gradient background and 'Right Image' written on it" />
</image-comparison>
<figcaption>
Comparing two base64 encoded SVGs in the default aspect ratio of 16/9.</p>
</figcaption>
</figure>
<figure class="otherstyle">
<image-comparison class="imgcompare" aspect-ratio="4/3">
<img class="before" src="https://picsum.photos/960/720?random=1" alt="A random image from Unsplash" />
<img class="after" src="https://picsum.photos/960/720?random=2" alt="Another random image from Unsplash" />
</image-comparison>
<figcaption>
Comparing two random images from Unsplash in a 4/3 aspect ratio. Also the style of the 'drag bar' is altered via CSS custom properties.
</figcaption>
</figure>
</main>
<script type="module" src="image-comparison.js"></script>
</body>
</html>