Elffuss BraidHub

kikocis/iscroll public

master · 5.0 KiBRawPermalink
1<!DOCTYPE html>
2<html>
3<head>
4<meta charset="utf-8">
5<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
6
7<title>iScroll demo: infinite scrolling</title>
8
9<script type="text/javascript" src="../../build/iscroll-infinite.js"></script>
10
11<script type="text/javascript">
12/******************************************************************************
13 *
14 * For the sake of keeping the script dependecy free I'm including a custom
15 * AJAX function. You should probably use a third party plugin
16 *
17 */
18function ajax (url, parms) {
19 parms = parms || {};
20 var req = new XMLHttpRequest(),
21 post = parms.post || null,
22 callback = parms.callback || null,
23 timeout = parms.timeout || null;
24
25 req.onreadystatechange = function () {
26 if ( req.readyState != 4 ) return;
27
28 // Error
29 if ( req.status != 200 && req.status != 304 ) {
30 if ( callback ) callback(false);
31 return;
32 }
33
34 if ( callback ) callback(req.responseText);
35 };
36
37 if ( post ) {
38 req.open('POST', url, true);
39 req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
40 } else {
41 req.open('GET', url, true);
42 }
43
44 req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
45
46 req.send(post);
47
48 if ( timeout ) {
49 setTimeout(function () {
50 req.onreadystatechange = function () {};
51 req.abort();
52 if ( callback ) callback(false);
53 }, timeout);
54 }
55}
56/*
57 *****************************************************************************/
58
59var myScroll;
60
61function loaded () {
62 myScroll = new IScroll('#wrapper', {
63 mouseWheel: true,
64 infiniteElements: '#scroller .row',
65 //infiniteLimit: 2000,
66 dataset: requestData,
67 dataFiller: updateContent,
68 cacheSize: 1000
69 });
70}
71
72function requestData (start, count) {
73 ajax('dataset.php?start=' + +start + '&count=' + +count, {
74 callback: function (data) {
75 data = JSON.parse(data);
76 myScroll.updateCache(start, data);
77 }
78 });
79}
80
81function updateContent (el, data) {
82 el.innerHTML = data;
83}
84
85document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
86
87</script>
88
89<style type="text/css">
90* {
91 -webkit-box-sizing: border-box;
92 -moz-box-sizing: border-box;
93 box-sizing: border-box;
94}
95
96html {
97 -ms-touch-action: none;
98}
99
100body,ul,li {
101 padding: 0;
102 margin: 0;
103 border: 0;
104}
105
106body {
107 font-size: 12px;
108 font-family: ubuntu, helvetica, arial;
109 overflow: hidden; /* this is important to prevent the whole page to bounce */
110}
111
112#header {
113 position: absolute;
114 z-index: 2;
115 top: 0;
116 left: 0;
117 width: 100%;
118 height: 45px;
119 line-height: 45px;
120 background: #CD235C;
121 padding: 0;
122 color: #eee;
123 font-size: 20px;
124 text-align: center;
125 font-weight: bold;
126}
127
128#footer {
129 position: absolute;
130 z-index: 2;
131 bottom: 0;
132 left: 0;
133 width: 100%;
134 height: 48px;
135 background: #444;
136 padding: 0;
137 border-top: 1px solid #444;
138}
139
140#wrapper {
141 position: absolute;
142 z-index: 1;
143 top: 45px;
144 bottom: 48px;
145 left: 0;
146 width: 100%;
147 background: #ccc;
148 overflow: hidden;
149}
150
151#scroller {
152 position: absolute;
153 z-index: 1;
154 -webkit-tap-highlight-color: rgba(0,0,0,0);
155 width: 100%;
156 -webkit-transform: translateZ(0);
157 -moz-transform: translateZ(0);
158 -ms-transform: translateZ(0);
159 -o-transform: translateZ(0);
160 transform: translateZ(0);
161 -webkit-touch-callout: none;
162 -webkit-user-select: none;
163 -moz-user-select: none;
164 -ms-user-select: none;
165 user-select: none;
166 -webkit-text-size-adjust: none;
167 -moz-text-size-adjust: none;
168 -ms-text-size-adjust: none;
169 -o-text-size-adjust: none;
170 text-size-adjust: none;
171}
172
173#scroller ul {
174 list-style: none;
175 padding: 0;
176 margin: 0;
177 width: 100%;
178 text-align: left;
179 position: relative;
180}
181
182#scroller li {
183 position: absolute;
184 width: 100%;
185 top: 0;
186 left: 0;
187 -webkit-transform: translateZ(0);
188 -moz-transform: translateZ(0);
189 -ms-transform: translateZ(0);
190 -o-transform: translateZ(0);
191 transform: translateZ(0);
192 padding: 0 10px;
193 height: 40px;
194 line-height: 40px;
195 border-bottom: 1px solid #ccc;
196 border-top: 1px solid #fff;
197 background-color: #fafafa;
198 font-size: 16px;
199}
200
201</style>
202</head>
203<body onload="loaded()">
204<div id="header">iScroll</div>
205
206<div id="wrapper">
207 <div id="scroller">
208 <ul>
209 <li class="row">Row 1</li>
210 <li class="row">Row 2</li>
211 <li class="row">Row 3</li>
212 <li class="row">Row 4</li>
213 <li class="row">Row 5</li>
214 <li class="row">Row 6</li>
215 <li class="row">Row 7</li>
216 <li class="row">Row 8</li>
217 <li class="row">Row 9</li>
218 <li class="row">Row 10</li>
219 <li class="row">Row 11</li>
220 <li class="row">Row 12</li>
221 <li class="row">Row 13</li>
222 <li class="row">Row 14</li>
223 <li class="row">Row 15</li>
224
225 <li class="row">Row 16</li>
226 <li class="row">Row 17</li>
227 <li class="row">Row 18</li>
228 <li class="row">Row 19</li>
229 <li class="row">Row 20</li>
230 <li class="row">Row 21</li>
231 <li class="row">Row 22</li>
232 <li class="row">Row 23</li>
233 <li class="row">Row 24</li>
234 <li class="row">Row 25</li>
235 <li class="row">Row 26</li>
236 <li class="row">Row 27</li>
237 <li class="row">Row 28</li>
238 <li class="row">Row 29</li>
239 <li class="row">Row 30</li>
240 </ul>
241 </div>
242</div>
243
244<div id="footer"></div>
245
246</body>
247</html>