mobile.js
6.6 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
/**
* @h5页面js
* @author:liuyue
* @date:2015-05-20
**/
define('mobile', function(require, exports) {
var $ = require('zepto'),
swipe = require("plugins/swipe"),
share = require("plugins/share"),
common = require("common"),
mlellipsis = require("plugins/mlellipsis");
require("plugins/imgZoom");
exports.index = function() {
//大banner滑动
swipe.init({
slideBox: '.slide-box',
pagination: '.dib a',
activeClass: 'on',
auto: 3000,
continuous: true
});
//频道点击效果
$('.channel-list').on('tap', 'li', function() {
$(this).addClass('current').siblings().removeClass('current');
})
};
exports.activity = function() {
$('.content-tab').on('click', 'li', function() {
var nowIndex = $(this).index();
$(this).addClass('current').siblings().removeClass('current');
$('.content-main').hide().eq(nowIndex).show();
});
};
exports.brand = function() {
var getBrand = function() {
var brand = $.trim($("input[type='text']").val());
var template = '<ul class="brand-list cooperation-list clearfix">{li}</ul>';
var noSearchTemplate = '<div class="no-search" style="display:block;"><p>未搜索到“{brand}”的相关品牌</p><a href="javascript:;" class="all_brand"><查看全部品牌</a></div>';
var html = '';
$.ajax({
type: "post",
url: "/brand/getbrand",
data: {
brand: brand
},
dataType: 'json',
success: function(data) {
var brands = data.data;
if (data.code == 200 && brands != "") {
$.each(brands, function(k, v) {
html += '<li><a href="/brand/detail/id/' + v.id + '" title="' + v.name + '"><div class="img-box">' +
'<img src="' + common.getImages(v.logo, '0145x0097', 'blogimg', 'primary') + '" alt="" alt="' + v.name + '"></div>' +
'<p>' + v.name + '</p></a></li>';
});
$(".brand-content").html(template.replace('{li}', html));
} else {
$(".brand-content").html(noSearchTemplate.replace('{brand}', brand));
}
}
});
};
//大banner滑动
swipe.init({
slideBox: '.slide-box',
pagination: '.dib a',
activeClass: 'on',
auto: 3000,
continuous: true
});
//搜索框获得焦点
$('.search-wrap input').on('focus', function() {
var offsetTop = $('.search-wrap').offset().top;
$('.overlay').addClass('show');
//document.body.scrollTop = offsetTop;
});
$('.search-wrap').find('input').on('keyup', function(event) {
var keycode = event.which;
if (keycode == 13) {
$('.search-wrap input').blur();
}
});
$('.search-btn').on('tap', function() {
$('.search-wrap input').focus().addClass('hasVal');
});
$('.search-wrap input').on('blur', function() {
var txtInput = $(this);
$('.overlay').removeClass('show');
if (txtInput.val() === '') {
txtInput.removeClass('hasVal');
} else {
txtInput.addClass('hasVal');
};
getBrand();
});
getBrand();
};
exports.scene = function() {
$('.scene-tab').on('tap', 'li', function() {
var nowIndex = $(this).index();
if ($(this).hasClass('disable')) return;
$(this).addClass('current').siblings().removeClass('current');
$('.main-layout').removeClass('current').eq(nowIndex).addClass('current');
});
$ = require('jquery');
$('.scene-content').find('.layout-item').each(function() {
//console.log($);
$(this).imgZoom();
});
};
exports.detail = function() {
var shareUrl = $(".share").attr("data-link"),
shareCover = $(".share").attr("cover-url"),
detailTitle = $('.detail-title').find('.title'),
detailSubtitle = $('.detail-title').find('.subtitle');
mlellipsis.init();
//大banner滑动
swipe.init({
slideBox: '.slide-box',
pagination: '.dib a',
activeClass: 'on',
auto: 3000,
continuous: true
});
//截字
$('.related-post').find('.content').each(function() {
$(this)[0].mlellipsis(2);
});
//分享
share.init({
shareUrl: shareUrl,
img: shareCover,
sinaText: '【YOHOOD 2015】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '@YOHO潮流志',
fbTextFunction: function() {
return {
des: '【YOHOOD 2015】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
name: '【YOHOOD 2015】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
caption: '【YOHOOD 2015】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
url: location.href
}
},
tweetText: '【YOHOOD 2015】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
qqText: '【YOHOOD 2015】' + detailTitle.text() + ' ' + detailSubtitle.text() + '#YOHOOD 2015'
});
};
exports.show = function() {
$(".layout-item").bind("tap", function(event) {
var imageWidth = $(window).width(),
imageHeight = 320;
$(this).find(".image-box .pic-tip").each(function() {
var style_top = parseInt($(this).attr("x")) / 10000 * imageHeight;
var style_left = parseInt($(this).attr("y")) / 10000 * imageWidth;
$(this).css({
top: style_top,
left: style_left,
display: "block"
});
});
});
};
exports.news = function() {
$('select').on('change', function() {
/* var nowIndex = $('option').not(function() {
return !this.selected
}).index();
$('.news-main').removeClass('current').eq(nowIndex).addClass('current');*/
window.location.href = $(this).val();
})
};
});