-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (92 loc) · 2.85 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
<!DOCTYPE html>
<html>
<head>
<title>aspectratio</title>
</head>
<body>
<style type="text/css">
h2, .description{
/*display: none!important;*/
}
.div1{
width: 1200px;
height: 200px;
max-width: 100%;
border: 3px solid blue;
margin-bottom: 5px;
box-sizing: border-box;
}
.div2{
border: 3px solid red;
}
div{
position: relative;
}
.size{
position: absolute;
left: 0;
right: 0;
margin: auto;
width: 180px;
text-align: center;
top: 50px;
font-size: 29px;
}
.name{
position: absolute;
width: 100%;
text-align: center;
top: 100px;
font-size: 32px;
}
.div1 .name {
color: blue;
}
.div2 .name {
color: red;
}
.description{
display: block;
color: #555;
text-align: center;
position: absolute;
width: 100%;
bottom: 30px;
}
</style>
<h2>Resize the window horizontally to see the effect</h2>
<div class="div1" >
<span class="size"></span>
<span class="name">Normal Div</span>
<span class="description">
The width is responsive (with width: 100%) but the height is always fixed to the initial value
</span>
</div>
<div class="div2 aspectratio" data-ar-width="1200" data-ar-height="200" data-ar-full_width="false">
<span class="size"></span>
<span class="name">Div with Aspect Ratio 1200/200</span>
<span class="description">
The height value is automatically calculated based on the width value
</span>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="aspectratiojs.js"></script>
<script>
var divs = $('div'), width, height;
(__resize = function () {
divs.each(function (i, div) {
div = $(div);
width = div.outerWidth();
height = div.outerHeight();
div.find('.size').text(width+' X '+height)
})
});
setTimeout(function() {
__resize();
}, 10);
$(window).resize(function(event) {
__resize();
});
</script>
</body>
</html>