-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
145 lines (123 loc) · 4.6 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ratiospy.js</title>
<style>
body {
font-family: sans-serif;
margin: 0;
}
.frame {
background: black;
box-sizing: border-box;
position: relative;
width: 18%;
height: 10em;
float: left;
overflow: hidden;
}
.frame + .frame {
margin-left: 2.5%;
}
/* fit child into frame */
.fit.child-landscape {
width: 100%;
height: auto;
}
.fit.child-portrait {
height: 100%;
width: auto;
}
/* cover frame w/ child */
.cover.child-portrait {
width: 100%;
height: auto;
}
.cover.child-landscape {
height: 100%;
width: auto;
}
.child-landscape,
.child-portrait {
/* centering */
position: absolute;
top: 50%;
left: 50%;
/* note:
* apart from being semi-elegant (note selection box)
* this won't work on Opera Mini
*/
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<h2>Applying styles and <code>fit</code> attribute</h2>
<div class="frame">
<svg class="fit" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="240" height="512" viewBox="0 0 240 512">
<rect x="0" y="0" width="240" height="512" fill="lightgray" />
</svg>
</div>
<div class="frame">
<svg class="fit" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="320" height="180" viewBox="0 0 320 180">
<rect x="0" y="0" width="320" height="180" fill="yellow" />
</svg>
</div>
<div class="frame">
<svg class="fit" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="480" height="480" viewBox="0 0 480 480">
<circle cx="240" cy="240" r="240" fill="red" />
</svg>
</div>
<div class="frame">
<svg class="fit" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1200" height="900" viewBox="0 0 1200 900">
<rect x="0" y="0" width="1200" height="900" fill="lime" />
</svg>
</div>
<div class="frame">
<svg class="fit" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="640" height="640" viewBox="0 0 640 640">
<rect x="0" y="0" width="640" height="640" fill="deeppink" />
</svg>
</div>
<h2>Applying styles and <code>cover</code> attribute</h2>
<div class="frame">
<svg class="cover" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="240" height="512" viewBox="0 0 240 512">
<rect x="0" y="0" width="240" height="512" fill="lightgray" />
</svg>
</div>
<div class="frame">
<svg class="cover" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="320" height="180" viewBox="0 0 320 180">
<rect x="0" y="0" width="320" height="180" fill="yellow" />
</svg>
</div>
<div class="frame">
<svg class="cover" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="480" height="480" viewBox="0 0 480 480">
<circle cx="240" cy="240" r="240" fill="red" />
</svg>
</div>
<div class="frame">
<svg class="cover" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1200" height="900" viewBox="0 0 1200 900">
<rect x="0" y="0" width="1200" height="900" fill="lime" />
</svg>
</div>
<div class="frame">
<svg class="cover" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="640" height="640" viewBox="0 0 640 640">
<rect x="0" y="0" width="640" height="640" fill="deeppink" />
</svg>
</div>
<script src="ratiospy.js"></script>
<script>
var frames = document.querySelectorAll('.frame');
//init
//TODO: pass `frames` element like ratiospy(frames)
var ratioWatcher = ratiospy();
//continuous updates
//TODO: behaves funky in Safari in resize: further testing
//TODO: throttle
//TODO: make standard param
window.onresize = function(){
ratioWatcher.update();
}
</script>
</body>
</html>