tencent.jquery.pix.component 1.0.6-6.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/banner/banner.js +461 -0
- package/components/banner/banner.scss +46 -0
- package/components/config.js +23 -0
- package/components/list/list.js +217 -0
- package/components/tips/tipv2.js +557 -0
- package/components/utils/env.js +7 -0
- package/components/utils/utils.js +65 -0
- package/components/video/resources/images/control-bg.png +0 -0
- package/components/video/resources/images/exit-full-screen.png +0 -0
- package/components/video/resources/images/full-screen.png +0 -0
- package/components/video/resources/images/mute.png +0 -0
- package/components/video/resources/images/origin-play.png +0 -0
- package/components/video/resources/images/pause.png +0 -0
- package/components/video/resources/images/play.png +0 -0
- package/components/video/resources/images/replay.png +0 -0
- package/components/video/resources/images/volume.png +0 -0
- package/components/video/videocss.scss +497 -0
- package/components/video/videohtml.js +85 -0
- package/components/video/videoplayer.js +425 -0
- package/components/waterfall/waterfall.js +819 -0
- package/components/waterfall/waterfall.scss +17 -0
- package/index.js +10 -0
- package/package.json +16 -0
- package/readme.md +15 -0
- package/utils/utils.js +16 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import "./banner.scss"
|
|
2
|
+
import { windowEnv, getEnv } from "../config";
|
|
3
|
+
import { addResizeFunc, nextAnimationFrame, removeResizeFunc } from "../utils/utils";
|
|
4
|
+
|
|
5
|
+
let $ = null;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 在页面上放置一个banner组件
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {object} options 选项
|
|
11
|
+
* @param {string} options.container 容器元素的jquery选择器
|
|
12
|
+
* @param {Array<{url: string, title: string}>} options.list 轮播图列表, url 为图片背景, title 为图片标题
|
|
13
|
+
* @param {number} [options.index=0] 轮播图初始位置
|
|
14
|
+
* @param {boolean} [options.isTitleEnabled=true] 是否启用标题、翻页栏
|
|
15
|
+
* @param {number} [options.durationMs=0] 轮播图切换时间间隔,单位毫秒,0表示不自动轮播,默认为 0
|
|
16
|
+
* @param {boolean} [options.autoResize=true] 是否自动调整容器宽度以适应屏幕宽度,默认为 true
|
|
17
|
+
* @param {number} [options.dragThreshold=0.2] 拖动翻页阈值,表示拖动距离占宽度的比例,默认为 0.2(20%)
|
|
18
|
+
* @param {function} [options.click] 点击轮播图时触发,第一个参数为触发元素的jq,第二个参数为 options.list 中对应的项,第三个参数为当前页码
|
|
19
|
+
* @param {function} [options.pageChanged] 翻页时触发,第一个参数为新生效页面元素的jq,第二个参数为 options.list 中对应的项,第三个参数为当前页码
|
|
20
|
+
* @param {function} [options.renderCallback] 自定义渲染回调,第一个参数为 options.list 中对应的项,第二个参数为当前页码,返回值为渲染后的元素
|
|
21
|
+
*/
|
|
22
|
+
export function Banner(options = {}) {
|
|
23
|
+
$ = getEnv().$;
|
|
24
|
+
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.options.isTitleEnabled ??= true;
|
|
27
|
+
this.options.autoResize ??= true;
|
|
28
|
+
this.options.durationMs = Number(options.durationMs || 0) || 0;
|
|
29
|
+
this.options.dragThreshold = Number(options.dragThreshold || 0.2) || 0.2;
|
|
30
|
+
this.index = Number(options.index || 0) || 0;
|
|
31
|
+
if (typeof options.renderCallback === 'function') {
|
|
32
|
+
this.options.isTitleEnabled = false;
|
|
33
|
+
}
|
|
34
|
+
this.init();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Banner.prototype.setWidth = function (width) {
|
|
38
|
+
this.signWidth = width;
|
|
39
|
+
this.allWidth = this.signWidth * (this.options.list.length + 2);
|
|
40
|
+
$(this.options.container).width(width);
|
|
41
|
+
this.$inner.width(this.allWidth);
|
|
42
|
+
this.$inner.find('.banner-inner-li').width(this.signWidth);
|
|
43
|
+
this.setTranslate(-this.signWidth * (this.index + 1));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Banner.prototype.fitWidth = function () {
|
|
47
|
+
console.log('banner fitWidth');
|
|
48
|
+
const newWidth = $(this.options.container).parent().width();
|
|
49
|
+
if (newWidth != this.signWidth) {
|
|
50
|
+
this.setWidth(newWidth);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 跳转到上一页
|
|
56
|
+
*/
|
|
57
|
+
Banner.prototype.prevPage = async function () {
|
|
58
|
+
this.pauseAutoPlay();
|
|
59
|
+
await this.gotoPageUnchecked(this.index - 1);
|
|
60
|
+
this.startAutoPlay();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 跳转到下一页
|
|
65
|
+
*/
|
|
66
|
+
Banner.prototype.nextPage = async function () {
|
|
67
|
+
this.pauseAutoPlay();
|
|
68
|
+
await this.gotoPageUnchecked(this.index + 1);
|
|
69
|
+
this.startAutoPlay();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 跳转到指定页
|
|
74
|
+
* @param {number} newIdx 要切换到的页码 [0, len)
|
|
75
|
+
*/
|
|
76
|
+
Banner.prototype.gotoPage = async function (newIdx) {
|
|
77
|
+
if (newIdx < 0 || newIdx >= this.options.list.length) {
|
|
78
|
+
throw new Error('index out of range');
|
|
79
|
+
}
|
|
80
|
+
if (newIdx == this.index) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
this.pauseAutoPlay();
|
|
84
|
+
await this.gotoPageUnchecked(newIdx);
|
|
85
|
+
this.startAutoPlay();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Banner.prototype.gotoPageUnchecked = async function (newIdx) {
|
|
89
|
+
const len = this.options.list.length;
|
|
90
|
+
let wrap = 0;
|
|
91
|
+
if (newIdx <= -1) {
|
|
92
|
+
newIdx = len - 1;
|
|
93
|
+
wrap = 1;
|
|
94
|
+
} else if (newIdx >= len) {
|
|
95
|
+
newIdx = 0;
|
|
96
|
+
wrap = -1;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (wrap !== 0) {
|
|
100
|
+
this.$inner.css('transition', 'none');
|
|
101
|
+
this.setTranslate(-this.signWidth * (newIdx + 1 + wrap));
|
|
102
|
+
await nextAnimationFrame();
|
|
103
|
+
await nextAnimationFrame();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.$inner.css('transition', 'transform 0.3s ease-out');
|
|
107
|
+
const newTranslate = -this.signWidth * (newIdx + 1);
|
|
108
|
+
this.setTranslate(newTranslate);
|
|
109
|
+
if (this.options.isTitleEnabled) {
|
|
110
|
+
this.$pagination.children().eq(newIdx + 1).addClass('active').siblings().removeClass('active');
|
|
111
|
+
this.$titleBox.text(this.options.list[newIdx].title);
|
|
112
|
+
}
|
|
113
|
+
if (this.options.pageChanged && newIdx != this.index) {
|
|
114
|
+
this.options.pageChanged(this.$inner.children().eq(newIdx + 1), this.options.list[newIdx], newIdx);
|
|
115
|
+
}
|
|
116
|
+
this.index = newIdx;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 获取当前页的序号
|
|
121
|
+
* @returns {number} 当前页的序号 [0,len]
|
|
122
|
+
*/
|
|
123
|
+
Banner.prototype.getCurrentPage = function () {
|
|
124
|
+
return this.index;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Banner.prototype.init = function () {
|
|
128
|
+
const $t = $(this.options.container)
|
|
129
|
+
console.log('banner container:', $t.dom);
|
|
130
|
+
const signWidth = $t.width()
|
|
131
|
+
$t.width(`${signWidth}px`);
|
|
132
|
+
$t.css('touch-action', 'none');
|
|
133
|
+
if (this.options.renderCallback) {
|
|
134
|
+
this.createCustomHtml();
|
|
135
|
+
} else {
|
|
136
|
+
this.createHtml();
|
|
137
|
+
}
|
|
138
|
+
this.bindEvent();
|
|
139
|
+
if (this.options.autoResize) {
|
|
140
|
+
addResizeFunc({
|
|
141
|
+
obj: this,
|
|
142
|
+
func: this.fitWidth,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
this.startAutoPlay();
|
|
146
|
+
console.log('list:', this.options.list, ' signWidth:', signWidth)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
Banner.prototype.startAutoPlay = function () {
|
|
150
|
+
if (this.options.durationMs > 0 && this.timer == null) {
|
|
151
|
+
this.timer = setInterval(() => {
|
|
152
|
+
this.nextPage()
|
|
153
|
+
}, this.options.durationMs);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
Banner.prototype.pauseAutoPlay = function () {
|
|
158
|
+
if (this.timer == null) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
clearInterval(this.timer);
|
|
162
|
+
this.timer = null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
Banner.prototype.createHtml = function () {
|
|
166
|
+
const len = this.options.list.length
|
|
167
|
+
if (len < 1) {
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
const $t = $(this.options.container)
|
|
171
|
+
$t.empty();
|
|
172
|
+
const signWidth = this.signWidth = $t.width()
|
|
173
|
+
|
|
174
|
+
const allWidth = this.allWidth = signWidth * (len + 2)
|
|
175
|
+
const $inner = this.$inner = $(`<div class="banner-inner-transform"></div>`)
|
|
176
|
+
this.currentTranslate = -signWidth * (this.index + 1)
|
|
177
|
+
$inner.width(allWidth).css('transform', `translateX(${this.currentTranslate}px)`)
|
|
178
|
+
|
|
179
|
+
// 加第0个位置
|
|
180
|
+
$inner.append(`<div class="banner-inner-li" data-background-url="${this.options.list[len - 1].url}" style="width:${this.signWidth}px;">
|
|
181
|
+
</div>
|
|
182
|
+
`)
|
|
183
|
+
for (let i = 0; i < len; i++) {
|
|
184
|
+
const item = this.options.list[i]
|
|
185
|
+
const $li = $(`<div class="banner-inner-li" data-background-url="${item.url}" style="width:${this.signWidth}px;">
|
|
186
|
+
</div>
|
|
187
|
+
`)
|
|
188
|
+
$inner.append($li)
|
|
189
|
+
}
|
|
190
|
+
// 加第N+1
|
|
191
|
+
$inner.append(`<div class="banner-inner-li" data-background-url="${this.options.list[0].url}" style="width:${this.signWidth}px;">
|
|
192
|
+
</div>
|
|
193
|
+
`)
|
|
194
|
+
|
|
195
|
+
const preloadIdx = this.index;
|
|
196
|
+
this.loadBackground(preloadIdx);
|
|
197
|
+
this.loadBackground((preloadIdx + 1) % len); // prev
|
|
198
|
+
this.loadBackground((preloadIdx - 1 + len) % len); // next
|
|
199
|
+
|
|
200
|
+
$t.append($inner)
|
|
201
|
+
|
|
202
|
+
if (this.options.isTitleEnabled) {
|
|
203
|
+
// 创建 titlebox
|
|
204
|
+
const $titleBox = $(`<div class="banner-title-box">${this.options.list[this.index].title}</div>`)
|
|
205
|
+
|
|
206
|
+
// 创建 pagination
|
|
207
|
+
const $pagination = $(`<div class="banner-pagination"></div>`)
|
|
208
|
+
|
|
209
|
+
$pagination.append($titleBox);
|
|
210
|
+
for (let i = 0; i < len; i++) {
|
|
211
|
+
$pagination.append(`<div class="banner-pagination-item ${i === 0 ? 'active' : ''}"></div>`)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this.$titleBox = $titleBox
|
|
215
|
+
this.$pagination = $pagination
|
|
216
|
+
|
|
217
|
+
$pagination.children().eq(this.index + 1).addClass('active').siblings().removeClass('active')
|
|
218
|
+
|
|
219
|
+
$t.append($pagination)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setTimeout(() => {
|
|
223
|
+
this.loadAllBackgrounds();
|
|
224
|
+
}, 1000);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 由 this.options.renderCallback 生成页面
|
|
229
|
+
*/
|
|
230
|
+
Banner.prototype.createCustomHtml = function () {
|
|
231
|
+
const len = this.options.list.length
|
|
232
|
+
if (len < 1) {
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
const $t = $(this.options.container)
|
|
236
|
+
$t.empty();
|
|
237
|
+
const signWidth = this.signWidth = $t.width()
|
|
238
|
+
|
|
239
|
+
const allWidth = this.allWidth = signWidth * (len + 2)
|
|
240
|
+
const $inner = this.$inner = $(`<div class="banner-inner-transform"></div>`)
|
|
241
|
+
this.currentTranslate = -signWidth * (this.index + 1)
|
|
242
|
+
$inner.width(allWidth).css('transform', `translateX(${this.currentTranslate}px)`)
|
|
243
|
+
|
|
244
|
+
let $li = $(this.options.renderCallback(this.options.list[len - 1], len - 1));
|
|
245
|
+
$li.width(signWidth);
|
|
246
|
+
$inner.append($li);
|
|
247
|
+
|
|
248
|
+
for (let i = 0; i < len; i++) {
|
|
249
|
+
$li = $(this.options.renderCallback(this.options.list[i], i));
|
|
250
|
+
$li.width(signWidth);
|
|
251
|
+
$inner.append($li);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
$li = $(this.options.renderCallback(this.options.list[0], 0));
|
|
255
|
+
$li.width(signWidth);
|
|
256
|
+
$inner.append($li);
|
|
257
|
+
|
|
258
|
+
$t.append($inner);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
Banner.prototype.bindEvent = function () {
|
|
262
|
+
const self = this
|
|
263
|
+
const len = this.options.list.length;
|
|
264
|
+
const $inner = this.$inner;
|
|
265
|
+
|
|
266
|
+
// pStart 时的 clientX
|
|
267
|
+
let originalX = 0;
|
|
268
|
+
|
|
269
|
+
// 随 pMove 的触发动态更新的 clientX
|
|
270
|
+
let startX = 0;
|
|
271
|
+
|
|
272
|
+
let originalTranslate = 0;
|
|
273
|
+
let isDown = false;
|
|
274
|
+
|
|
275
|
+
const pStart = (x, capture) => {
|
|
276
|
+
if (isDown) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (capture) {
|
|
280
|
+
capture();
|
|
281
|
+
}
|
|
282
|
+
this.pauseAutoPlay();
|
|
283
|
+
originalX = x;
|
|
284
|
+
startX = x;
|
|
285
|
+
originalTranslate = this.currentTranslate;
|
|
286
|
+
$inner.css('transition', 'none')
|
|
287
|
+
isDown = true;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const pMove = x => {
|
|
291
|
+
if (!isDown) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const curX = x;
|
|
295
|
+
const moveX = curX - startX;
|
|
296
|
+
let newTranslate = this.currentTranslate + moveX;
|
|
297
|
+
if (Math.abs(newTranslate - originalTranslate) > this.signWidth) {
|
|
298
|
+
// 限制滑动范围不超过一个 sign 的宽度
|
|
299
|
+
newTranslate = Math.max(Math.min(newTranslate, originalTranslate + this.signWidth), originalTranslate - this.signWidth);
|
|
300
|
+
} else {
|
|
301
|
+
startX = curX;
|
|
302
|
+
}
|
|
303
|
+
this.setTranslate(newTranslate);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const pEnd = async (capture) => {
|
|
307
|
+
if (!isDown) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (capture) {
|
|
311
|
+
capture();
|
|
312
|
+
}
|
|
313
|
+
isDown = false;
|
|
314
|
+
// let newTranslate = Math.round(this.currentTranslate / this.signWidth) * this.signWidth;
|
|
315
|
+
// newTranslate = Math.max(Math.min(newTranslate, 0), -this.signWidth * (len+1));
|
|
316
|
+
let newTranslate;
|
|
317
|
+
if (Math.abs(this.currentTranslate - originalTranslate) > this.signWidth * this.options.dragThreshold) {
|
|
318
|
+
newTranslate = Math.sign(this.currentTranslate - originalTranslate) * this.signWidth + originalTranslate;
|
|
319
|
+
if (newTranslate > -this.signWidth) {
|
|
320
|
+
newTranslate -= this.signWidth * len;
|
|
321
|
+
} else if (newTranslate < -this.signWidth * len) {
|
|
322
|
+
newTranslate += this.signWidth * len;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// 在移动到新位置前,先变换当前位置到正确区域
|
|
326
|
+
await this.normalizeTranslate();
|
|
327
|
+
} else {
|
|
328
|
+
newTranslate = originalTranslate;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
$inner.css('transition', 'transform 0.3s ease-out')
|
|
332
|
+
$inner.css('transform', `translateX(${this.currentTranslate}px)`);
|
|
333
|
+
|
|
334
|
+
if (newTranslate !== this.currentTranslate) {
|
|
335
|
+
this.setTranslate(newTranslate);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// 计算 newIndex ,取值范围 [0, len)
|
|
339
|
+
// 由于 newTranslate 包含了前后的循环占位(位置 0 和 len+1 ),需要减1后取模
|
|
340
|
+
const newIndex = (Math.round(-newTranslate / this.signWidth) + len - 1) % len;
|
|
341
|
+
if (this.options.isTitleEnabled) {
|
|
342
|
+
this.$pagination.children().eq(newIndex + 1).addClass('active').siblings().removeClass('active');
|
|
343
|
+
this.$titleBox.text(this.options.list[newIndex].title);
|
|
344
|
+
}
|
|
345
|
+
if (this.options.pageChanged && newIndex != this.index) {
|
|
346
|
+
this.options.pageChanged(this.$inner.children().eq(newIndex + 1), this.options.list[newIndex], newIndex);
|
|
347
|
+
}
|
|
348
|
+
this.index = newIndex;
|
|
349
|
+
this.startAutoPlay();
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
$inner.off();
|
|
353
|
+
|
|
354
|
+
if (windowEnv === 'h5') { // 浏览器环境
|
|
355
|
+
$inner
|
|
356
|
+
.attr('draggable', 'false')
|
|
357
|
+
.on('pointerdown', function (e) {
|
|
358
|
+
pStart(e.originalEvent.clientX, () => {
|
|
359
|
+
this.setPointerCapture(e.originalEvent.pointerId);
|
|
360
|
+
});
|
|
361
|
+
})
|
|
362
|
+
.on('pointermove', function (e) {
|
|
363
|
+
pMove(e.originalEvent.clientX);
|
|
364
|
+
})
|
|
365
|
+
.on('pointerup', async function (e) {
|
|
366
|
+
await pEnd(() => {
|
|
367
|
+
this.releasePointerCapture(e.originalEvent.pointerId);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
} else { // app或模拟器
|
|
371
|
+
$inner
|
|
372
|
+
.attr('draggable', 'true')
|
|
373
|
+
.on('dragstart', e => {
|
|
374
|
+
pStart(e.clientX);
|
|
375
|
+
})
|
|
376
|
+
.on('drag', e => {
|
|
377
|
+
pMove(e.clientX);
|
|
378
|
+
})
|
|
379
|
+
.on('dragend', async () => {
|
|
380
|
+
await pEnd();
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
$inner.on('transitionend', () => {
|
|
385
|
+
$inner.css('transition', 'none');
|
|
386
|
+
})
|
|
387
|
+
.on('click', function (e) {
|
|
388
|
+
if (!self.options.click) {
|
|
389
|
+
return
|
|
390
|
+
}
|
|
391
|
+
if (windowEnv === 'h5' && Math.abs(e.clientX - originalX) > 10) {
|
|
392
|
+
// 防止浏览器中拖动时触发click
|
|
393
|
+
return
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const $t = self.$inner.children().eq(self.index + 1);
|
|
397
|
+
self.options.click($t, self.options.list[self.index], self.index);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
Banner.prototype.setTranslate = function (transX) {
|
|
402
|
+
this.currentTranslate = transX;
|
|
403
|
+
this.$inner.css('transform', `translateX(${this.currentTranslate}px)`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 当currentTranslate位于补位区时,平移一个周期到另一侧
|
|
408
|
+
* 如果需要移动,则使用requestAnimationFrame确保动作完成
|
|
409
|
+
*/
|
|
410
|
+
Banner.prototype.normalizeTranslate = async function () {
|
|
411
|
+
const len = this.options.list.length;
|
|
412
|
+
if (this.currentTranslate > -this.signWidth) {
|
|
413
|
+
this.setTranslate(this.currentTranslate - this.signWidth * len);
|
|
414
|
+
await nextAnimationFrame();
|
|
415
|
+
await nextAnimationFrame();
|
|
416
|
+
} else if (this.currentTranslate < -this.signWidth * len) {
|
|
417
|
+
this.setTranslate(this.currentTranslate + this.signWidth * len);
|
|
418
|
+
await nextAnimationFrame();
|
|
419
|
+
await nextAnimationFrame();
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 加载所有背景图片,将data-background-url属性设置为背景图片
|
|
425
|
+
*/
|
|
426
|
+
Banner.prototype.loadAllBackgrounds = function () {
|
|
427
|
+
this.$inner.children().each(function () {
|
|
428
|
+
$(this).css('background-image', `url(${$(this).attr('data-background-url')})`)
|
|
429
|
+
});
|
|
430
|
+
// console.log('banner images loaded');
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* 加载背景图片,将data-background-url属性设置为背景图片
|
|
435
|
+
* @param {number} pos 为加载的图片编号,取值[0, len),如果为0或len-1,会同时加载滚动占位的图片
|
|
436
|
+
*/
|
|
437
|
+
Banner.prototype.loadBackground = function (pos) {
|
|
438
|
+
console.log('loadBackground pos === ', pos);
|
|
439
|
+
let $item = this.$inner.children().eq(pos + 1);
|
|
440
|
+
$item.css('background-image', `url(${$item.attr('data-background-url')})`);
|
|
441
|
+
|
|
442
|
+
// 加载滚动占位的图片
|
|
443
|
+
if (pos === 0) {
|
|
444
|
+
$item = this.$inner.children().eq(this.options.list.length + 1);
|
|
445
|
+
$item.css('background-image', `url(${$item.attr('data-background-url')})`);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (pos === this.options.list.length - 1) {
|
|
449
|
+
$item = this.$inner.children().eq(0);
|
|
450
|
+
$item.css('background-image', `url(${$item.attr('data-background-url')})`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
Banner.prototype.remove = function () {
|
|
455
|
+
this.pauseAutoPlay();
|
|
456
|
+
$(this.options.container).empty();
|
|
457
|
+
removeResizeFunc({
|
|
458
|
+
obj: this,
|
|
459
|
+
func: this.fitWidth,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
.banner-inner-transform {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: row;
|
|
4
|
+
height: 100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.banner-pagination-item {
|
|
8
|
+
flex-shrink: 0;
|
|
9
|
+
width: 0.2rem;
|
|
10
|
+
height: 0.2rem;
|
|
11
|
+
background: rgba(255, 255, 255, 0.5);
|
|
12
|
+
margin: 0 0.075rem;
|
|
13
|
+
border-radius: 50%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.banner-pagination {
|
|
17
|
+
display: flex;
|
|
18
|
+
position: absolute;
|
|
19
|
+
bottom: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
height: 0.6rem;
|
|
22
|
+
width: 100%;
|
|
23
|
+
background: rgba(0, 0, 0, 0.7);
|
|
24
|
+
justify-content: flex-end;
|
|
25
|
+
align-items: center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.banner-pagination-item.active {
|
|
29
|
+
background: #fff;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.banner-title-box {
|
|
33
|
+
flex-shrink: 1;
|
|
34
|
+
bottom: 0;
|
|
35
|
+
left: 0;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: 0.6rem;
|
|
38
|
+
display: flex;
|
|
39
|
+
justify-content: start;
|
|
40
|
+
font-size: 0.36rem;
|
|
41
|
+
align-items: center;
|
|
42
|
+
z-index: 10;
|
|
43
|
+
text-wrap: nowrap;
|
|
44
|
+
overflow: hidden;
|
|
45
|
+
color: white;
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { startEventResize, startEventScroll } from './utils/utils.js'
|
|
2
|
+
|
|
3
|
+
export let windowEnv;
|
|
4
|
+
export let $;
|
|
5
|
+
|
|
6
|
+
export const setEnv = (config) => {
|
|
7
|
+
windowEnv = config.windowEnv;
|
|
8
|
+
$ = config.$;
|
|
9
|
+
console.log('setEnv', config);
|
|
10
|
+
|
|
11
|
+
// 页面resize事件
|
|
12
|
+
startEventResize();
|
|
13
|
+
|
|
14
|
+
// 页面scroll事件
|
|
15
|
+
startEventScroll($)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const getEnv = () => {
|
|
19
|
+
return {
|
|
20
|
+
windowEnv,
|
|
21
|
+
$,
|
|
22
|
+
}
|
|
23
|
+
}
|