Showing
2 changed files
with
108 additions
and
1 deletions
@@ -160,6 +160,48 @@ $header.on('touchstart', 'a', function() { | @@ -160,6 +160,48 @@ $header.on('touchstart', 'a', function() { | ||
160 | $(this).removeClass('highlight'); | 160 | $(this).removeClass('highlight'); |
161 | }); | 161 | }); |
162 | 162 | ||
163 | +(function() { | ||
164 | + var lastTime = 0; | ||
165 | + var prefixes = 'webkit moz ms o'.split(' '); | ||
166 | + | ||
167 | + var requestAnimationFrame = window.requestAnimationFrame; | ||
168 | + var cancelAnimationFrame = window.cancelAnimationFrame; | ||
169 | + | ||
170 | + var prefix; | ||
171 | + | ||
172 | + //通过遍历各浏览器前缀,来得到requestAnimationFrame和cancelAnimationFrame在当前浏览器的实现形式 | ||
173 | + for( var i = 0; i < prefixes.length; i++ ) { | ||
174 | + if ( requestAnimationFrame && cancelAnimationFrame ) { | ||
175 | + break; | ||
176 | + } | ||
177 | + prefix = prefixes[i]; | ||
178 | + requestAnimationFrame = requestAnimationFrame || window[ prefix + 'RequestAnimationFrame' ]; | ||
179 | + cancelAnimationFrame = cancelAnimationFrame || window[ prefix + 'CancelAnimationFrame' ] || window[ prefix + 'CancelRequestAnimationFrame' ]; | ||
180 | + } | ||
181 | + | ||
182 | + //如果当前浏览器不支持requestAnimationFrame和cancelAnimationFrame,则会退到setTimeout | ||
183 | + if ( !requestAnimationFrame || !cancelAnimationFrame ) { | ||
184 | + requestAnimationFrame = function( callback, element ) { | ||
185 | + var currTime = new Date().getTime(); | ||
186 | + | ||
187 | + //为了使setTimteout的尽可能的接近每秒60帧的效果 | ||
188 | + var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) ); | ||
189 | + var id = window.setTimeout( function() { | ||
190 | + callback( currTime + timeToCall ); | ||
191 | + }, timeToCall ); | ||
192 | + lastTime = currTime + timeToCall; | ||
193 | + return id; | ||
194 | + }; | ||
195 | + | ||
196 | + cancelAnimationFrame = function( id ) { | ||
197 | + window.clearTimeout( id ); | ||
198 | + }; | ||
199 | + } | ||
200 | + | ||
201 | + window.requestAnimationFrame = requestAnimationFrame; | ||
202 | + window.cancelAnimationFrame = cancelAnimationFrame; | ||
203 | +}()); | ||
204 | + | ||
163 | 205 | ||
164 | //暴露公共接口 | 206 | //暴露公共接口 |
165 | window.cookie = cookie; | 207 | window.cookie = cookie; |
@@ -2,4 +2,69 @@ | @@ -2,4 +2,69 @@ | ||
2 | * 商品详情 | 2 | * 商品详情 |
3 | * @author: liangzhifeng<zhifeng.liang@yoho.cn> | 3 | * @author: liangzhifeng<zhifeng.liang@yoho.cn> |
4 | * @date: 2015/11/18 | 4 | * @date: 2015/11/18 |
5 | - */ | ||
5 | + */ | ||
6 | +var $ = require('jquery'), | ||
7 | + Hammer = require('yoho.hammer'), | ||
8 | + tip = require('../plugin/tip'), | ||
9 | + loading = require('../plugin/loading'), | ||
10 | + lazyLoad = require('yoho.lazyload'); | ||
11 | + | ||
12 | +var loading = require('../../plugin/loading'); | ||
13 | + | ||
14 | +var navHammer, | ||
15 | + winH = $(window).height(), | ||
16 | + searching = false, | ||
17 | + num, | ||
18 | + url; | ||
19 | + | ||
20 | +function scrollHandler() { | ||
21 | + if ($(window).scrollTop() + winH >= $(document).height() - 50) { | ||
22 | + //search(); | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +function search() { | ||
27 | + if (searching) { | ||
28 | + return; | ||
29 | + } | ||
30 | + searching = true; | ||
31 | + | ||
32 | + loading.showLoadingMask(); | ||
33 | + | ||
34 | + //num = $goodList.find('.good-info').length; | ||
35 | + $.ajax({ | ||
36 | + type: 'GET', | ||
37 | + url: url, | ||
38 | + data: { | ||
39 | + page: page + 1 | ||
40 | + }, | ||
41 | + success: function(data) { | ||
42 | + | ||
43 | + num = $goodList.find('.good-info').length; | ||
44 | + | ||
45 | + $goodList.append(data); | ||
46 | + | ||
47 | + // 2015/10/31 fei.hong: 修复第一页分页不显示图片的问题 | ||
48 | + if (num === 0) { | ||
49 | + lazyLoad($goodList.find('.good-info').find('img.lazy')); | ||
50 | + } else { | ||
51 | + lazyLoad($goodList.find('.good-info:gt(' + (num - 1) + ')').find('img.lazy')); | ||
52 | + } | ||
53 | + | ||
54 | + searching = false; | ||
55 | + loading.hideLoadingMask(); | ||
56 | + page++; | ||
57 | + }, | ||
58 | + error: function() { | ||
59 | + tip.show('网络断开连接了~'); | ||
60 | + searching = false; | ||
61 | + loading.hideLoadingMask(); | ||
62 | + } | ||
63 | + }); | ||
64 | +} | ||
65 | + | ||
66 | +//srcoll to load more | ||
67 | +$(window).scroll(function () { | ||
68 | + window.requestAnimationFrame(scrollHandler); | ||
69 | +}); | ||
70 | + |
-
Please register or login to post a comment