-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.html
86 lines (81 loc) · 2.34 KB
/
example.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
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>jQuery viewport plugin</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html,
body {
padding: 0;
margin: 0;
}
.item {
display: block;
position: absolute;
left: 0px;
width: 100%;
background: #f00;
color: #fff;
font-size: 50px;
text-align: center;
border: 3px solid #e00;
box-sizing: border-box;
}
#item-1 {
top: 50px;
height: 100px;
line-height: 100px;
}
#item-2 {
top: 200px;
height: 400px;
line-height: 400px;
}
#item-3 {
top: 650px;
height: 800px;
line-height: 800px;
}
#item-4 {
top: 1500px;
height: 1600px;
line-height: 1600px;
margin-bottom: 50px;
}
.console {
position: fixed;
top: 0;
right: 0;
padding: 20px;
background: #eee;
}
</style>
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="item" id="item-1">1</div>
<div class="item" id="item-2">2</div>
<div class="item" id="item-3">3</div>
<div class="item" id="item-4">4</div>
<div class="console"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="jquery.viewport.js"></script>
<script>
$(function(){
var items = $('.item');
items.mostVisible();
$(window).on('scroll', function(){
var strings = items.map(function(){
return this.innerText + ': ' + $.inViewport(this).toFixed(6);
}).toArray();
$('.console').html(strings.join('<br>'));
}).trigger('scroll');
});
</script>
</body>
</html>