update for make the recommend-for-you be sent after scroll. code review by LZF
Showing
1 changed file
with
22 additions
and
3 deletions
@@ -10,9 +10,20 @@ var Swiper = require('yoho.iswiper'), | @@ -10,9 +10,20 @@ var Swiper = require('yoho.iswiper'), | ||
10 | 10 | ||
11 | var recommendSwiper, | 11 | var recommendSwiper, |
12 | $recommendForYou = $('.recommend-for-you'), | 12 | $recommendForYou = $('.recommend-for-you'), |
13 | - preferenceUrl = $('#preferenceUrl').val(); | 13 | + preferenceUrl = $('#preferenceUrl').val(), |
14 | + winH = $(window).height(), | ||
15 | + end = false, | ||
16 | + requesting = false; | ||
14 | 17 | ||
15 | -if (preferenceUrl) { | 18 | + |
19 | +function request() { | ||
20 | + if (requesting || end) { | ||
21 | + return; | ||
22 | + } | ||
23 | + | ||
24 | + requesting = true; | ||
25 | + | ||
26 | + if (preferenceUrl) { | ||
16 | $.get(preferenceUrl).then(function(html) { | 27 | $.get(preferenceUrl).then(function(html) { |
17 | if (html.length < 5) { | 28 | if (html.length < 5) { |
18 | $recommendForYou.css('display', 'none'); | 29 | $recommendForYou.css('display', 'none'); |
@@ -29,9 +40,17 @@ if (preferenceUrl) { | @@ -29,9 +40,17 @@ if (preferenceUrl) { | ||
29 | } | 40 | } |
30 | } | 41 | } |
31 | 42 | ||
32 | - window.rePosFooter(); | 43 | + requesting = false; |
44 | + end = true; | ||
33 | 45 | ||
34 | }).fail(function() { | 46 | }).fail(function() { |
35 | $recommendForYou.hide(); | 47 | $recommendForYou.hide(); |
36 | }); | 48 | }); |
49 | + } | ||
37 | } | 50 | } |
51 | + | ||
52 | +$(window).scroll(function() { | ||
53 | + if (!end || $(window).scrollTop() + winH >= $(document).height() - 50) { | ||
54 | + request(); | ||
55 | + } | ||
56 | +}); |
-
Please register or login to post a comment