Authored by 梁志锋

店铺优化2

@@ -121,9 +121,7 @@ if ($('.category-list li').length % 4 !== 0) { @@ -121,9 +121,7 @@ if ($('.category-list li').length % 4 !== 0) {
121 if ($('.category-list li').length < 4) { 121 if ($('.category-list li').length < 4) {
122 $('.category-list').addClass('category-list-top-board'); 122 $('.category-list').addClass('category-list-top-board');
123 $('.category-list').find('.buriedpoint').addClass('category-list-only-one-row'); 123 $('.category-list').find('.buriedpoint').addClass('category-list-only-one-row');
124 -}  
125 -  
126 -if ($('.category-list li').length >= 5) { 124 +} else if ($('.category-list li').length >= 5) {
127 for (listIndex = listModValue; listIndex >= 0; listIndex--) { 125 for (listIndex = listModValue; listIndex >= 0; listIndex--) {
128 $('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row'); 126 $('.category-list li').eq(listCount - 4 + listIndex - 1).addClass('category-list-last-full-row');
129 } 127 }
@@ -190,7 +188,7 @@ function newData(callback) { @@ -190,7 +188,7 @@ function newData(callback) {
190 req.callBack = function(data) { 188 req.callBack = function(data) {
191 $('#new-arrival').append(data); 189 $('#new-arrival').append(data);
192 navInfo.new.page++; 190 navInfo.new.page++;
193 - myScroll.refresh(); 191 + //myScroll.refresh();
194 lazyLoad($('#new-arrival .lazy')); 192 lazyLoad($('#new-arrival .lazy'));
195 scH = $('#scroller').outerHeight(); 193 scH = $('#scroller').outerHeight();
196 searching = false; 194 searching = false;
@@ -215,7 +213,7 @@ function hotData(callback) { @@ -215,7 +213,7 @@ function hotData(callback) {
215 req.callBack = function(data) { 213 req.callBack = function(data) {
216 $('#popularity').append(data); 214 $('#popularity').append(data);
217 navInfo.hot.page++; 215 navInfo.hot.page++;
218 - myScroll.refresh(); 216 + //myScroll.refresh();
219 lazyLoad($('#popularity .lazy')); 217 lazyLoad($('#popularity .lazy'));
220 scH = $('#scroller').outerHeight(); 218 scH = $('#scroller').outerHeight();
221 searching = false; 219 searching = false;
@@ -232,11 +230,7 @@ function tabChange(dom, index) { @@ -232,11 +230,7 @@ function tabChange(dom, index) {
232 } 230 }
233 231
234 232
235 -myScroll = new IScroll('#wrapper', {  
236 - probeType: 3,  
237 - mouseWheel: true,  
238 - click: true  
239 -}); 233 +
240 234
241 //首页导航 235 //首页导航
242 (function(nav, posNav, main) { 236 (function(nav, posNav, main) {
@@ -263,7 +257,7 @@ myScroll = new IScroll('#wrapper', { @@ -263,7 +257,7 @@ myScroll = new IScroll('#wrapper', {
263 viewType = 3; 257 viewType = 3;
264 } else if (activeTab === 'home-page') { 258 } else if (activeTab === 'home-page') {
265 259
266 - myScroll && myScroll.refresh(); 260 + //myScroll && myScroll.refresh();
267 scH = $('#scroller').outerHeight(); 261 scH = $('#scroller').outerHeight();
268 $nav1.removeClass('fixed-top absolute'); 262 $nav1.removeClass('fixed-top absolute');
269 $nav2.removeClass('fixed-top absolute'); 263 $nav2.removeClass('fixed-top absolute');
@@ -319,7 +313,8 @@ function reNav1Pos() { @@ -319,7 +313,8 @@ function reNav1Pos() {
319 } 313 }
320 } 314 }
321 315
322 -myScroll.on('scroll', function() { 316 +
  317 +function scrollHandler() {
323 var scrollCall, 318 var scrollCall,
324 sTop = -this.y; 319 sTop = -this.y;
325 320
@@ -428,27 +423,7 @@ myScroll.on('scroll', function() { @@ -428,27 +423,7 @@ myScroll.on('scroll', function() {
428 }); 423 });
429 } 424 }
430 } 425 }
431 -});  
432 -  
433 -myScroll.on('scrollStart', function() {  
434 -  
435 - // stop auto play when scroll  
436 - bannerSwiper && bannerSwiper.stopAutoplay();  
437 -  
438 - multiSwiper && multiSwiper.stopAutoplay();  
439 -});  
440 -  
441 -myScroll.on('scrollEnd', function() {  
442 -  
443 - // start auto play when scroll end  
444 - bannerSwiper && bannerSwiper.startAutoplay();  
445 -  
446 - multiSwiper && multiSwiper.startAutoplay();  
447 -  
448 - $('#scroller').trigger('scroll');  
449 -});  
450 -  
451 - 426 +}
452 427
453 document.addEventListener('touchmove', function(e) { 428 document.addEventListener('touchmove', function(e) {
454 // sub classify不阻止默认事件 429 // sub classify不阻止默认事件
@@ -462,18 +437,50 @@ document.addEventListener('touchmove', function(e) { @@ -462,18 +437,50 @@ document.addEventListener('touchmove', function(e) {
462 }*/ 437 }*/
463 438
464 439
465 -//window onload 后重新refresh iscroll  
466 -$(window).load(function() {  
467 - myScroll && myScroll.refresh(); 440 +//window ready 后重新refresh iscroll
  441 +$(window).ready(function() {
  442 + //myScroll && myScroll.refresh();
468 imgH = $('#nav-top').outerHeight(); 443 imgH = $('#nav-top').outerHeight();
469 nav1H = $('#nav').outerHeight(); 444 nav1H = $('#nav').outerHeight();
470 main1H = $('#nav-main').height(); 445 main1H = $('#nav-main').height();
471 main1oH = $('#nav-main').outerHeight(); 446 main1oH = $('#nav-main').outerHeight();
472 nav2H = $('#list-nav').outerHeight(); 447 nav2H = $('#list-nav').outerHeight();
473 main2oH = $('#goods-container').outerHeight(); 448 main2oH = $('#goods-container').outerHeight();
474 - setTimeout(function() { 449 +
  450 +
  451 + myScroll = new IScroll('#wrapper', {
  452 + probeType: 2,
  453 + mouseWheel: false,
  454 + click: true
  455 + });
  456 +
  457 + //setTimeout(function() {
475 scH = $('#scroller').outerHeight(); 458 scH = $('#scroller').outerHeight();
476 - }, 1000); 459 + //}, 1000);
  460 +
  461 +
  462 + myScroll.on('scroll', function() {
  463 + window.requestAnimationFrame(scrollHandler);
  464 + });
  465 +
  466 + myScroll.on('scrollStart', function() {
  467 +
  468 + // stop auto play when scroll
  469 + bannerSwiper && bannerSwiper.stopAutoplay();
  470 +
  471 + multiSwiper && multiSwiper.stopAutoplay();
  472 + });
  473 +
  474 + myScroll.on('scrollEnd', function() {
  475 +
  476 + // start auto play when scroll end
  477 + bannerSwiper && bannerSwiper.startAutoplay();
  478 +
  479 + multiSwiper && multiSwiper.startAutoplay();
  480 +
  481 + $('#scroller').trigger('scroll');
  482 + });
  483 +
477 }); 484 });
478 485
479 function bindGoodThumbClick() { 486 function bindGoodThumbClick() {
@@ -639,7 +646,10 @@ function search(opt) { @@ -639,7 +646,10 @@ function search(opt) {
639 646
640 window.rePosFooter(); 647 window.rePosFooter();
641 648
642 - myScroll.refresh(); 649 + setTimeout(function() {
  650 + myScroll && myScroll.refresh();
  651 + }, 0);
  652 +
643 reNav1Pos(); 653 reNav1Pos();
644 654
645 bindGoodThumbClick(); 655 bindGoodThumbClick();
@@ -682,14 +692,14 @@ $subNav.on('touchend touchcancel', function(e) { @@ -682,14 +692,14 @@ $subNav.on('touchend touchcancel', function(e) {
682 $pre.addClass('active'); 692 $pre.addClass('active');
683 $this.removeClass('active'); 693 $this.removeClass('active');
684 694
685 - myScroll.enable(); 695 + myScroll && myScroll.enable();
686 } else { 696 } else {
687 $pre = $this.siblings('.active'); 697 $pre = $this.siblings('.active');
688 698
689 $pre.removeClass('active'); 699 $pre.removeClass('active');
690 $this.addClass('active'); 700 $this.addClass('active');
691 701
692 - myScroll.scrollTo(0, -(imgH + main1oH + nav1H)); 702 + myScroll && myScroll.scrollTo(0, -(imgH + main1oH + nav1H));
693 703
694 theY = imgH + main1oH + nav1H; 704 theY = imgH + main1oH + nav1H;
695 705
@@ -703,7 +713,7 @@ $subNav.on('touchend touchcancel', function(e) { @@ -703,7 +713,7 @@ $subNav.on('touchend touchcancel', function(e) {
703 $('.filter-mask').removeClass('call-by-fix').css('top', $this.offset().top + nav1H); 713 $('.filter-mask').removeClass('call-by-fix').css('top', $this.offset().top + nav1H);
704 } 714 }
705 715
706 - myScroll.disable(); 716 + myScroll && myScroll.disable();
707 } 717 }
708 } else { 718 } else {
709 if ($this.hasClass('new')) { 719 if ($this.hasClass('new')) {
@@ -717,7 +727,7 @@ $subNav.on('touchend touchcancel', function(e) { @@ -717,7 +727,7 @@ $subNav.on('touchend touchcancel', function(e) {
717 navType = 'discount'; 727 navType = 'discount';
718 } 728 }
719 729
720 - myScroll.enable(); 730 + myScroll && myScroll.enable();
721 731
722 nav = navInfo[navType]; 732 nav = navInfo[navType];
723 733
@@ -803,7 +813,7 @@ $subNav.on('touchend touchcancel', function(e) { @@ -803,7 +813,7 @@ $subNav.on('touchend touchcancel', function(e) {
803 filter.initFilter({ 813 filter.initFilter({
804 fCbFn: function(option) { 814 fCbFn: function(option) {
805 search(option); 815 search(option);
806 - myScroll.enable(); 816 + myScroll && myScroll.enable();
807 }, 817 },
808 hCbFn: function() { 818 hCbFn: function() {
809 819
@@ -811,7 +821,7 @@ filter.initFilter({ @@ -811,7 +821,7 @@ filter.initFilter({
811 $pre.addClass('active'); 821 $pre.addClass('active');
812 $pre.siblings('.filter').removeClass('active'); 822 $pre.siblings('.filter').removeClass('active');
813 823
814 - myScroll.enable(); 824 + myScroll && myScroll.enable();
815 }, 825 },
816 missStatus: true 826 missStatus: true
817 }); 827 });
@@ -820,14 +830,14 @@ $listNav.on('touchstart', 'li', function(e) { @@ -820,14 +830,14 @@ $listNav.on('touchstart', 'li', function(e) {
820 $(this).addClass('bytouch'); 830 $(this).addClass('bytouch');
821 }).on('touchend touchcancel', function() { 831 }).on('touchend touchcancel', function() {
822 $listNav.find('li').removeClass('bytouch'); 832 $listNav.find('li').removeClass('bytouch');
823 - myScroll.refresh(); 833 + //myScroll && myScroll.refresh();
824 }); 834 });
825 835
826 $nav2.on('touchstart', 'li', function(e) { 836 $nav2.on('touchstart', 'li', function(e) {
827 $(this).addClass('bytouch'); 837 $(this).addClass('bytouch');
828 }).on('touchend touchcancel', function() { 838 }).on('touchend touchcancel', function() {
829 $nav2.find('li').removeClass('bytouch'); 839 $nav2.find('li').removeClass('bytouch');
830 - myScroll.refresh(); 840 + //myScroll && myScroll.refresh();
831 }); 841 });
832 842
833 //底部导航点击 843 //底部导航点击
@@ -890,7 +900,7 @@ function postCollect(info) { @@ -890,7 +900,7 @@ function postCollect(info) {
890 } 900 }
891 901
892 setTimeout(function() { 902 setTimeout(function() {
893 - myScroll.refresh(); 903 + //myScroll.refresh();
894 scH = $('#scroller').outerHeight(); 904 scH = $('#scroller').outerHeight();
895 }, 1000); 905 }, 1000);
896 searching = false; 906 searching = false;
@@ -44,7 +44,8 @@ @@ -44,7 +44,8 @@
44 {{#each multiList}} 44 {{#each multiList}}
45 <li class="swiper-slide brand-img buriedpoint" data-bp-id="shop_brand_{{img}}_0"> 45 <li class="swiper-slide brand-img buriedpoint" data-bp-id="shop_brand_{{img}}_0">
46 <a href="{{url}}"> 46 <a href="{{url}}">
47 - <img src="{{img}}"> 47 +<!-- <img src="{{img}}">-->
  48 + <img class="lazy" data-original="{{img}}" alt="">
48 </a> 49 </a>
49 <p>{{brandName}}</p> 50 <p>{{brandName}}</p>
50 </li> 51 </li>
@@ -64,7 +65,8 @@ @@ -64,7 +65,8 @@
64 {{#each spring}} 65 {{#each spring}}
65 <li class="buriedpoint" data-bp-id="shop_spring_{{img}}_0" > 66 <li class="buriedpoint" data-bp-id="shop_spring_{{img}}_0" >
66 <a href="{{url}}"> 67 <a href="{{url}}">
67 - <img src="{{springType}}"> 68 +<!-- <img src="{{springType}}">-->
  69 + <img class="lazy" data-original="{{springType}}" alt="">
68 </a> 70 </a>
69 </li> 71 </li>
70 {{/each}} 72 {{/each}}