yohood.js
6.3 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
define('yohood', function(require, exports) {
var swipe = require("plugins/swipe");
var $ = require("jquery");
var freetile = require("lib/ui/jquery.freetile");
var goodsSwiper;
require("plugins/pagination");
//设置瀑布流
function setFlowLayout() {
$('.fluid-list-inner').freetile({
animate: false,
elementDelay: 0
});
}
//设置商品滚动条
function setGoodsSwiper() {
var limitedPrev,
limitedNext,
swiperLen;
//限量商品滑动
goodsSwiper = swipe.init({
slideBox: '.limited-slide-box',
prev: '.limited-slide-prev',
next: '.limited-slide-next',
auto: false,
});
limitedPrev = $('.limited-slide-prev');
limitedNext = $('.limited-slide-next');
limitedPrev.addClass('disable');
limitedNext.on('click', function() {
limitedPrev.removeClass('disable');
swiperLen = $('.limited-slide-box').find('.box').size();
if (goodsSwiper.getPos() === swiperLen - 1) {
$(this).addClass('disable');
};
});
limitedPrev.on('click', function() {
limitedNext.removeClass('disable');
if (goodsSwiper.getPos() === 0) {
$(this).addClass('disable');
};
});
}
//获取推荐商品
function getRecommendProduct(obj, limit) {
var template = '<div class="box"><ul class="goods-list clearfix">{li}</ul></div>';
var offset = parseInt(obj.attr("offset"));
var temp = '';
var html = '';
$.ajax
({
url:"/product/getrecommend",
type:"post",
data:{offset:offset, limit:limit},
success:function(data)
{
var product = data.data, pic = '', pos = offset , part, topClass = '';
if(data.code == 200 && product !="")
{
$.each(product, function(i, v)
{
pic = v.pic.split('|')[0].replace(/-(\w+)-/g, '-0150x0200-');
parts = v.price.split('.');
topClass = pos>2 ? '':'red';
html +='<li><a href="'+v.url+'" target="_blank" title="'+v.name+'">' +
'<div class="img-box"><img src="'+ pic +'" alt=""><span class="'+topClass+'">TOP '+(++pos)+'</span></div>'+
'<p class="goods-name">'+v.name+'</p>'+
'<p class="price">¥'+( parts[0] + '.'+ ( parts[1] ? parts[1] : '00' ) )+'</p></a></li>';
if(pos %5 == 0)
{
temp += template.replace('{li}', html);
html = '';
}
});
if(pos % 5 != 0 )
{
temp += template.replace('{li}', html);
}
obj.append(temp);
obj.attr("offset", pos);
if(offset<=0)
{
setGoodsSwiper();
}
else
{
//重新绘画
goodsSwiper.setup();
$('.limited-slide-next').removeClass('disable');
}
}
}
});
return html;
}
//yohood展会页面
exports.exhibition = function() {
swipe.init({
slideBox: '.slide-box-exhibition',
prev: '.slide-prev-exhibition',
next: '.slide-next-exhibition',
pagination: '.dib a',
activeClass: 'on',
auto: 3000,
continuous: true
});
}
//首页
exports.index = function() {
var cooperateSwiper,
cooperatePrev,
cooperateNext;
//大banner滑动
swipe.init({
slideBox: '.slide-box',
prev: '.slide-prev',
next: '.slide-next',
pagination: '.dib a',
activeClass: 'on',
auto: 3000,
continuous: true
});
cooperateSwiper = swipe.init({
slideBox: '.cooperation-slide-box',
prev: '.cooperation-slide-prev',
next: '.cooperation-slide-next',
auto: false
});
cooperatePrev = $('.cooperation-slide-prev');
cooperateNext = $('.cooperation-slide-next');
swiperLen = $('.cooperation-slide-box').find('.box').size();
cooperatePrev.addClass('disable');
cooperateNext.on('click', function() {
cooperatePrev.removeClass('disable');
if (cooperateSwiper.getPos() === swiperLen - 1) {
$(this).addClass('disable');
};
});
cooperatePrev.on('click', function() {
cooperateNext.removeClass('disable');
if (cooperateSwiper.getPos() === 0) {
$(this).addClass('disable');
};
});
setFlowLayout();
};
//资讯
exports.news = function() {
setFlowLayout();
}
//show页面
exports.show = function() {
$(".look_big_image").bind("click", function(event) {
var divName = '#mask';
var sourceImage = $(this).attr("source");
var imageWidth = parseInt($(divName).children().attr("width"));
var imageHeight = parseInt($(divName).children().attr("height"));
$(divName).html('<img src="' + sourceImage + '" width="' + imageWidth + '" height="' + imageHeight + '" />').attr("current_class", $(this).parent().attr("class"));
var top = ($(window).height() - imageHeight) / 2;
var left = ($(window).width() - imageWidth) / 2;
var scrollTop = 0; //$(document).scrollTop();
var scrollLeft = 0; //$(document).scrollLeft();
$(divName).css({
position: 'absolute',
'top': top + scrollTop,
left: left + scrollLeft
});
$(".model").show();
if (left - 75 > 10) {
$(".image-prev").css("left", left - 75);
$(".image-next").css("right", left - 75);
}
$.each($(this).parents("span").children("span"), function(index, dom) {
var style_top = parseInt($(dom).attr("x")) / 10000 * imageHeight;
var style_left = parseInt($(dom).attr("y")) / 10000 * imageWidth;
$(divName).append('<a class="pic-tip" style="left:' + style_left + 'px;top:' + style_top + 'px;">' + $(dom).attr("label") + '</a>')
});
event.stopPropagation();
});
$(".image-next, .image-prev").bind("click", function() {
var current_class = $("#mask").attr("current_class");
var pos = parseInt(current_class.replace('single_', ''));
if ($(this).attr("class").indexOf("image-next") != -1) {
pos = pos + 1;
} else {
pos = pos - 1;
}
if ($(".single_" + pos).size() > 0) {
$(".single_" + pos).find(".look_big_image").click();
}
});
$(".ui-dialog-close").bind("click", function(event) {
$(".model").hide();
event.stopPropagation();
});
}
//整个页面布局
exports.layout = function()
{
getRecommendProduct($("#product_list"), 20);
//点击
$(".limited-slide-next").bind("click", function()
{
getRecommendProduct($("#product_list"), 20);
});
//回到顶部
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$(".return-top").fadeIn(500);
} else {
$(".return-top").fadeOut(500);
}
});
$(".return-top").click(function() {
$('body,html').animate({
scrollTop: 0
}, 500);
return false;
});
}
//活动
exports.activity = function()
{
}
});