detail.js
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* 商品详情
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/20
*/
var $ = require('jquery'),
Swiper = require('yoho.iswiper'),
Hammer = require('yoho.hammer'),
lazyLoad = require('yoho.lazyload');
var goodsSwiper,
$discountFolder = $('.goodsDiscount .discount-folder'),
$discountArrow = $('.goodsDiscount .first-item span');
var goodsDiscountEl = document.getElementById('goodsDiscount'),
goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl),
$discountFirstItem = $(goodsDiscountEl).find('.first-item');
var $cart = $('.cart-bar');
require('./desc');
require('./comments-consults');
require('../recommend-for-you-product-desc');
//add extra marign-bottom for footer to show the yoho copyright
function showFooter() {
var $cartBar = $('.cart-bar');
var timer = setInterval(function() {
if ($cartBar) {
window.reMarginFooter('.cart-bar');
clearInterval(timer);
} else {
$cartBar = $('.cart-bar');
}
}, 200);
}
showFooter();
lazyLoad($('img.lazy'));
//顶部swiper
goodsSwiper = new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
paginationClickable: true,
pagination: '.banner-top .pagination-inner',
nextButton: '.my-swiper-button-next',
prevButton: '.my-swiper-button-prev',
spaceBetween: 3
});
//初始化goods-discount
if (0 === $discountFolder.children().length) {
$discountFolder.css('display', 'none');
$discountArrow.html('');
}
//goods-discount下拉按钮点击事件
if (goodsDiscountHammer && $discountFolder.children().length > 0) {
goodsDiscountHammer.on('tap', function(e) {
if ($discountFolder.is(':hidden')) {
$discountFirstItem.removeClass('short-text');
$discountArrow.removeClass('icon-down').addClass('icon-up').html('');
$discountFolder.slideDown();
} else {
$discountFirstItem.addClass('short-text');
$discountArrow.removeClass('icon-up').addClass('icon-down').html('');
$discountFolder.slideUp();
}
});
}
//购物车商品数量
$.ajax({
type: 'GET',
url: '/cart/index/count',
success: function(data) {
if (data.code === 200) {
$cart.find('.num-tag').html(data.data.cart_goods_count).removeClass('hide');
}
}
});
if ($('.good-detail-page').length > 0) {
$('#yoho-footer').css('border-top', '1px solid #e0e0e0');
}
require('./like');