Authored by Lynnic

js代码优化

@@ -7,7 +7,10 @@ @@ -7,7 +7,10 @@
7 Swiper = require('yoho.iswiper'), 7 Swiper = require('yoho.iswiper'),
8 lazyLoad = require('yoho.lazyload'); 8 lazyLoad = require('yoho.lazyload');
9 9
10 -var goodsSwiper; 10 +var goodsSwiper,
  11 + $discountFolder = $('.goods-discount .discount-folder'),
  12 + $discountArrow = $('.goodsDiscount .first-item span');
  13 +
11 14
12 require('./desc'); 15 require('./desc');
13 require('./comments-consults'); 16 require('./comments-consults');
@@ -29,18 +32,18 @@ goodsSwiper = new Swiper('.banner-swiper', { @@ -29,18 +32,18 @@ goodsSwiper = new Swiper('.banner-swiper', {
29 32
30 //初始化goods-discount 33 //初始化goods-discount
31 if (0 === $('.goods-discount .discount-folder').children().length) { 34 if (0 === $('.goods-discount .discount-folder').children().length) {
32 - $('.goods-discount .discount-folder').css('display', 'none');  
33 - $('.goods-discount .first-item span').html(''); 35 + $discountFolder.css('display', 'none');
  36 + $discountArrow.html('');
34 } 37 }
35 38
36 //goods-discount下拉按钮点击事件 39 //goods-discount下拉按钮点击事件
37 $('.goodsDiscount .dropdown').on('click', function() { 40 $('.goodsDiscount .dropdown').on('click', function() {
38 - if ($('.goodsDiscount .discount-folder').is(':hidden')) {  
39 - $('.goodsDiscount .first-item span').removeClass('icon-down').addClass('icon-up').html('');  
40 - $('.goodsDiscount .discount-folder').slideDown(); 41 + if ($discountFolder.is(':hidden')) {
  42 + $discountArrow.removeClass('icon-down').addClass('icon-up').html('');
  43 + $discountFolder.slideDown();
41 } else { 44 } else {
42 - $('.goodsDiscount .first-item span').removeClass('icon-up').addClass('icon-down').html('');  
43 - $('.goodsDiscount .discount-folder').slideUp(); 45 + $discountArrow.removeClass('icon-up').addClass('icon-down').html('');
  46 + $discountFolder.slideUp();
44 } 47 }
45 }); 48 });
46 require('./like'); 49 require('./like');