Authored by biao

update for make the recommend-for-you be sent after scroll. code review by LZF

@@ -10,28 +10,47 @@ var Swiper = require('yoho.iswiper'), @@ -10,28 +10,47 @@ 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();  
14 -  
15 -if (preferenceUrl) {  
16 - $.get(preferenceUrl).then(function(html) {  
17 - if (html.length < 5) {  
18 - $recommendForYou.css('display', 'none');  
19 - } else {  
20 - $recommendForYou.html(html).show();  
21 - if ($('#swiper-recommend').length) {  
22 - recommendSwiper = new Swiper('#swiper-recommend', {  
23 - slidesPerView: 'auto',  
24 - grabCursor: true,  
25 - slideElement: 'a',  
26 - lazyLoading: true,  
27 - watchSlidesVisibility: true  
28 - }); 13 + preferenceUrl = $('#preferenceUrl').val(),
  14 + winH = $(window).height(),
  15 + end = false,
  16 + requesting = false;
  17 +
  18 +
  19 +function request() {
  20 + if (requesting || end) {
  21 + return;
  22 + }
  23 +
  24 + requesting = true;
  25 +
  26 + if (preferenceUrl) {
  27 + $.get(preferenceUrl).then(function(html) {
  28 + if (html.length < 5) {
  29 + $recommendForYou.css('display', 'none');
  30 + } else {
  31 + $recommendForYou.html(html).show();
  32 + if ($('#swiper-recommend').length) {
  33 + recommendSwiper = new Swiper('#swiper-recommend', {
  34 + slidesPerView: 'auto',
  35 + grabCursor: true,
  36 + slideElement: 'a',
  37 + lazyLoading: true,
  38 + watchSlidesVisibility: true
  39 + });
  40 + }
29 } 41 }
30 - }  
31 42
32 - window.rePosFooter(); 43 + requesting = false;
  44 + end = true;
33 45
34 - }).fail(function() {  
35 - $recommendForYou.hide();  
36 - }); 46 + }).fail(function() {
  47 + $recommendForYou.hide();
  48 + });
  49 + }
37 } 50 }
  51 +
  52 +$(window).scroll(function() {
  53 + if (!end || $(window).scrollTop() + winH >= $(document).height() - 50) {
  54 + request();
  55 + }
  56 +});