-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
95 lines (91 loc) · 2.15 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
<!DOCTYPE>
<html>
<body>
<style>
ul,li{
-webkit-margin-before: 0px;
-webkit-margin-after: 0px;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 0px;
}
.box {
display:block;
position:absolute;
height:50px;
background-color:#FF0000;
margin:0;
padding:0;
margin-top:50px;
float:left;
clear:none;
}
</style>
<script src="res.js"></script>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var r = new res([{
"state": "mobile",
"breakpoint": 640,
"cols": 4,
"margin": 20,
"gutter": 10
},
{
"state": "small",
"breakpoint": 1024,
"cols": 12,
"margin": 40,
"gutter": 20
},
{
"state": "desktop",
"breakpoint": 1920,
"cols": 16,
"margin": 80,
"gutter": 20
}
]);
window.addEventListener('stateChange',function(ev){
console.log(r);
$('.box:eq(0)').text('state: '+r.state);
$('.box:eq(1)').text('browser: '+r.browser);
$('.box:eq(2)').text('os: '+r.os);
$('.box:eq(3)').text('columns: '+r.grid.cols);
switch(r.state) {
case 'mobile':
$('.box').each(function(){
$(this).css('width',r.grid.colSpan[4]);
$(this).css('top',80*$(this).index()+'px');
$(this).css('left',r.grid.col[0]);
});
break;
case 'small':
$('.box').css('top','0px');
$('.box').css('width',r.grid.colSpan[6]);
$('.box:eq(0)').css('left',r.grid.col[0]);
$('.box:eq(1)').css('left',r.grid.col[6]);
$('.box:eq(2)').css('top',$('.box:eq(0)').height()+20);
$('.box:eq(2)').css('left',r.grid.col[0]);
$('.box:eq(3)').css('top',$('.box:eq(0)').height()+20);
$('.box:eq(3)').css('left',r.grid.col[6]);
break;
case 'desktop':
$('.box').css('width',r.grid.colSpan[4]);
$('.box').css('top','0px');
$('.box:eq(0)').css('left',r.grid.col[0]);
$('.box:eq(1)').css('left',r.grid.col[4]);
$('.box:eq(2)').css('left',r.grid.col[8]);
$('.box:eq(3)').css('left',r.grid.col[12]);
break;
}
});
</script>
<ul>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
<li class="box"></li>
</ul>
</body>
</html>