tencent.jquery.pix.component 1.0.63-beta.3 → 1.0.63-beta.4
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import "./banner.scss"
|
|
2
|
-
import {
|
|
2
|
+
import { windowEnv, getEnv } from "../config";
|
|
3
3
|
import { addResizeFunc, nextAnimationFrame, removeResizeFunc } from "../utils/utils";
|
|
4
4
|
|
|
5
|
+
let $ = null;
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* 在页面上放置一个banner组件
|
|
7
9
|
* @constructor
|
|
@@ -17,7 +19,9 @@ import { addResizeFunc, nextAnimationFrame, removeResizeFunc } from "../utils/ut
|
|
|
17
19
|
* @param {function} [options.pageChanged] 翻页时触发,第一个参数为新生效页面元素的jq,第二个参数为 options.list 中对应的项,第三个参数为当前页码
|
|
18
20
|
* @param {function} [options.renderCallback] 自定义渲染回调,第一个参数为 options.list 中对应的项,第二个参数为当前页码,返回值为渲染后的元素
|
|
19
21
|
*/
|
|
20
|
-
export function Banner(options = {}){
|
|
22
|
+
export function Banner(options = {}) {
|
|
23
|
+
$ = getEnv().$;
|
|
24
|
+
|
|
21
25
|
this.options = options;
|
|
22
26
|
this.options.isTitleEnabled ??= true;
|
|
23
27
|
this.options.autoResize ??= true;
|
|
@@ -30,7 +34,7 @@ export function Banner(options = {}){
|
|
|
30
34
|
this.init();
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
Banner.prototype.setWidth = function(width) {
|
|
37
|
+
Banner.prototype.setWidth = function (width) {
|
|
34
38
|
this.signWidth = width;
|
|
35
39
|
this.allWidth = this.signWidth * (this.options.list.length + 2);
|
|
36
40
|
$(this.options.container).width(width);
|
|
@@ -39,7 +43,7 @@ Banner.prototype.setWidth = function(width) {
|
|
|
39
43
|
this.setTranslate(-this.signWidth * (this.index + 1));
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
Banner.prototype.fitWidth = function() {
|
|
46
|
+
Banner.prototype.fitWidth = function () {
|
|
43
47
|
console.log('banner fitWidth');
|
|
44
48
|
const newWidth = $(this.options.container).parent().width();
|
|
45
49
|
if (newWidth != this.signWidth) {
|
|
@@ -50,7 +54,7 @@ Banner.prototype.fitWidth = function() {
|
|
|
50
54
|
/**
|
|
51
55
|
* 跳转到上一页
|
|
52
56
|
*/
|
|
53
|
-
Banner.prototype.prevPage = async function() {
|
|
57
|
+
Banner.prototype.prevPage = async function () {
|
|
54
58
|
this.pauseAutoPlay();
|
|
55
59
|
await this.gotoPageUnchecked(this.index - 1);
|
|
56
60
|
this.startAutoPlay();
|
|
@@ -59,7 +63,7 @@ Banner.prototype.prevPage = async function() {
|
|
|
59
63
|
/**
|
|
60
64
|
* 跳转到下一页
|
|
61
65
|
*/
|
|
62
|
-
Banner.prototype.nextPage = async function() {
|
|
66
|
+
Banner.prototype.nextPage = async function () {
|
|
63
67
|
this.pauseAutoPlay();
|
|
64
68
|
await this.gotoPageUnchecked(this.index + 1);
|
|
65
69
|
this.startAutoPlay();
|
|
@@ -69,7 +73,7 @@ Banner.prototype.nextPage = async function() {
|
|
|
69
73
|
* 跳转到指定页
|
|
70
74
|
* @param {number} newIdx 要切换到的页码 [0, len)
|
|
71
75
|
*/
|
|
72
|
-
Banner.prototype.gotoPage = async function(newIdx) {
|
|
76
|
+
Banner.prototype.gotoPage = async function (newIdx) {
|
|
73
77
|
if (newIdx < 0 || newIdx >= this.options.list.length) {
|
|
74
78
|
throw new Error('index out of range');
|
|
75
79
|
}
|
|
@@ -81,7 +85,7 @@ Banner.prototype.gotoPage = async function(newIdx) {
|
|
|
81
85
|
this.startAutoPlay();
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
Banner.prototype.gotoPageUnchecked = async function(newIdx) {
|
|
88
|
+
Banner.prototype.gotoPageUnchecked = async function (newIdx) {
|
|
85
89
|
const len = this.options.list.length;
|
|
86
90
|
let wrap = 0;
|
|
87
91
|
if (newIdx <= -1) {
|
|
@@ -100,14 +104,14 @@ Banner.prototype.gotoPageUnchecked = async function(newIdx) {
|
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
this.$inner.css('transition', 'transform 0.3s ease-out');
|
|
103
|
-
const newTranslate = -this.signWidth * (newIdx+1);
|
|
107
|
+
const newTranslate = -this.signWidth * (newIdx + 1);
|
|
104
108
|
this.setTranslate(newTranslate);
|
|
105
109
|
if (this.options.isTitleEnabled) {
|
|
106
|
-
this.$pagination.children().eq(newIdx+1).addClass('active').siblings().removeClass('active');
|
|
110
|
+
this.$pagination.children().eq(newIdx + 1).addClass('active').siblings().removeClass('active');
|
|
107
111
|
this.$titleBox.text(this.options.list[newIdx].title);
|
|
108
112
|
}
|
|
109
113
|
if (this.options.pageChanged && newIdx != this.index) {
|
|
110
|
-
this.options.pageChanged(this.$inner.children().eq(newIdx+1), this.options.list[newIdx], newIdx);
|
|
114
|
+
this.options.pageChanged(this.$inner.children().eq(newIdx + 1), this.options.list[newIdx], newIdx);
|
|
111
115
|
}
|
|
112
116
|
this.index = newIdx;
|
|
113
117
|
}
|
|
@@ -116,11 +120,11 @@ Banner.prototype.gotoPageUnchecked = async function(newIdx) {
|
|
|
116
120
|
* 获取当前页的序号
|
|
117
121
|
* @returns {number} 当前页的序号 [0,len]
|
|
118
122
|
*/
|
|
119
|
-
Banner.prototype.getCurrentPage = function() {
|
|
123
|
+
Banner.prototype.getCurrentPage = function () {
|
|
120
124
|
return this.index;
|
|
121
125
|
}
|
|
122
126
|
|
|
123
|
-
Banner.prototype.init = function(){
|
|
127
|
+
Banner.prototype.init = function () {
|
|
124
128
|
const $t = $(this.options.container)
|
|
125
129
|
console.log('banner container:', $t.dom);
|
|
126
130
|
const signWidth = $t.width()
|
|
@@ -139,10 +143,10 @@ Banner.prototype.init = function(){
|
|
|
139
143
|
});
|
|
140
144
|
}
|
|
141
145
|
this.startAutoPlay();
|
|
142
|
-
console.log('list:', this.options.list, ' signWidth:',signWidth)
|
|
146
|
+
console.log('list:', this.options.list, ' signWidth:', signWidth)
|
|
143
147
|
}
|
|
144
148
|
|
|
145
|
-
Banner.prototype.startAutoPlay = function() {
|
|
149
|
+
Banner.prototype.startAutoPlay = function () {
|
|
146
150
|
if (this.options.durationMs > 0 && this.timer == null) {
|
|
147
151
|
this.timer = setInterval(() => {
|
|
148
152
|
this.nextPage()
|
|
@@ -150,7 +154,7 @@ Banner.prototype.startAutoPlay = function() {
|
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
Banner.prototype.pauseAutoPlay = function() {
|
|
157
|
+
Banner.prototype.pauseAutoPlay = function () {
|
|
154
158
|
if (this.timer == null) {
|
|
155
159
|
return;
|
|
156
160
|
}
|
|
@@ -158,25 +162,25 @@ Banner.prototype.pauseAutoPlay = function() {
|
|
|
158
162
|
this.timer = null;
|
|
159
163
|
}
|
|
160
164
|
|
|
161
|
-
Banner.prototype.createHtml = function(){
|
|
165
|
+
Banner.prototype.createHtml = function () {
|
|
162
166
|
const len = this.options.list.length
|
|
163
|
-
if(len<1){
|
|
167
|
+
if (len < 1) {
|
|
164
168
|
return
|
|
165
169
|
}
|
|
166
170
|
const $t = $(this.options.container)
|
|
167
171
|
$t.empty();
|
|
168
172
|
const signWidth = this.signWidth = $t.width()
|
|
169
|
-
|
|
173
|
+
|
|
170
174
|
const allWidth = this.allWidth = signWidth * (len + 2)
|
|
171
175
|
const $inner = this.$inner = $(`<div class="banner-inner-transform"></div>`)
|
|
172
176
|
this.currentTranslate = -signWidth * (this.index + 1)
|
|
173
|
-
$inner.width(allWidth).css('transform'
|
|
177
|
+
$inner.width(allWidth).css('transform', `translateX(${this.currentTranslate}px)`)
|
|
174
178
|
|
|
175
179
|
// 加第0个位置
|
|
176
|
-
$inner.append(`<div class="banner-inner-li" data-background-url="${this.options.list[len-1].url}" style="width:${this.signWidth}px;">
|
|
180
|
+
$inner.append(`<div class="banner-inner-li" data-background-url="${this.options.list[len - 1].url}" style="width:${this.signWidth}px;">
|
|
177
181
|
</div>
|
|
178
182
|
`)
|
|
179
|
-
for(let i=0;i<len;i++){
|
|
183
|
+
for (let i = 0; i < len; i++) {
|
|
180
184
|
const item = this.options.list[i]
|
|
181
185
|
const $li = $(`<div class="banner-inner-li" data-background-url="${item.url}" style="width:${this.signWidth}px;">
|
|
182
186
|
</div>
|
|
@@ -210,7 +214,7 @@ Banner.prototype.createHtml = function(){
|
|
|
210
214
|
this.$titleBox = $titleBox
|
|
211
215
|
this.$pagination = $pagination
|
|
212
216
|
|
|
213
|
-
$pagination.children().eq(this.index+1).addClass('active').siblings().removeClass('active')
|
|
217
|
+
$pagination.children().eq(this.index + 1).addClass('active').siblings().removeClass('active')
|
|
214
218
|
|
|
215
219
|
$t.append($pagination)
|
|
216
220
|
}
|
|
@@ -223,21 +227,21 @@ Banner.prototype.createHtml = function(){
|
|
|
223
227
|
/**
|
|
224
228
|
* 由 this.options.renderCallback 生成页面
|
|
225
229
|
*/
|
|
226
|
-
Banner.prototype.createCustomHtml = function() {
|
|
230
|
+
Banner.prototype.createCustomHtml = function () {
|
|
227
231
|
const len = this.options.list.length
|
|
228
|
-
if(len<1){
|
|
232
|
+
if (len < 1) {
|
|
229
233
|
return
|
|
230
234
|
}
|
|
231
235
|
const $t = $(this.options.container)
|
|
232
236
|
$t.empty();
|
|
233
237
|
const signWidth = this.signWidth = $t.width()
|
|
234
|
-
|
|
238
|
+
|
|
235
239
|
const allWidth = this.allWidth = signWidth * (len + 2)
|
|
236
240
|
const $inner = this.$inner = $(`<div class="banner-inner-transform"></div>`)
|
|
237
241
|
this.currentTranslate = -signWidth * (this.index + 1)
|
|
238
|
-
$inner.width(allWidth).css('transform'
|
|
242
|
+
$inner.width(allWidth).css('transform', `translateX(${this.currentTranslate}px)`)
|
|
239
243
|
|
|
240
|
-
let $li = $(this.options.renderCallback(this.options.list[len-1], len-1));
|
|
244
|
+
let $li = $(this.options.renderCallback(this.options.list[len - 1], len - 1));
|
|
241
245
|
$li.width(signWidth);
|
|
242
246
|
$inner.append($li);
|
|
243
247
|
|
|
@@ -254,7 +258,7 @@ Banner.prototype.createCustomHtml = function() {
|
|
|
254
258
|
$t.append($inner);
|
|
255
259
|
}
|
|
256
260
|
|
|
257
|
-
Banner.prototype.bindEvent = function(){
|
|
261
|
+
Banner.prototype.bindEvent = function () {
|
|
258
262
|
const self = this
|
|
259
263
|
const len = this.options.list.length;
|
|
260
264
|
const $inner = this.$inner;
|
|
@@ -317,7 +321,7 @@ Banner.prototype.bindEvent = function(){
|
|
|
317
321
|
} else if (newTranslate < -this.signWidth * len) {
|
|
318
322
|
newTranslate += this.signWidth * len;
|
|
319
323
|
}
|
|
320
|
-
|
|
324
|
+
|
|
321
325
|
// 在移动到新位置前,先变换当前位置到正确区域
|
|
322
326
|
await this.normalizeTranslate();
|
|
323
327
|
} else {
|
|
@@ -325,7 +329,7 @@ Banner.prototype.bindEvent = function(){
|
|
|
325
329
|
}
|
|
326
330
|
|
|
327
331
|
$inner.css('transition', 'transform 0.3s ease-out')
|
|
328
|
-
$inner.css('transform'
|
|
332
|
+
$inner.css('transform', `translateX(${this.currentTranslate}px)`);
|
|
329
333
|
|
|
330
334
|
if (newTranslate !== this.currentTranslate) {
|
|
331
335
|
this.setTranslate(newTranslate);
|
|
@@ -335,11 +339,11 @@ Banner.prototype.bindEvent = function(){
|
|
|
335
339
|
// 由于 newTranslate 包含了前后的循环占位(位置 0 和 len+1 ),需要减1后取模
|
|
336
340
|
const newIndex = (Math.round(-newTranslate / this.signWidth) + len - 1) % len;
|
|
337
341
|
if (this.options.isTitleEnabled) {
|
|
338
|
-
this.$pagination.children().eq(newIndex+1).addClass('active').siblings().removeClass('active');
|
|
342
|
+
this.$pagination.children().eq(newIndex + 1).addClass('active').siblings().removeClass('active');
|
|
339
343
|
this.$titleBox.text(this.options.list[newIndex].title);
|
|
340
344
|
}
|
|
341
345
|
if (this.options.pageChanged && newIndex != this.index) {
|
|
342
|
-
this.options.pageChanged(this.$inner.children().eq(newIndex+1), this.options.list[newIndex], newIndex);
|
|
346
|
+
this.options.pageChanged(this.$inner.children().eq(newIndex + 1), this.options.list[newIndex], newIndex);
|
|
343
347
|
}
|
|
344
348
|
this.index = newIndex;
|
|
345
349
|
this.startAutoPlay();
|
|
@@ -350,15 +354,15 @@ Banner.prototype.bindEvent = function(){
|
|
|
350
354
|
if (windowEnv === 'h5') { // 浏览器环境
|
|
351
355
|
$inner
|
|
352
356
|
.attr('draggable', 'false')
|
|
353
|
-
.on('pointerdown', function(e) {
|
|
357
|
+
.on('pointerdown', function (e) {
|
|
354
358
|
pStart(e.originalEvent.clientX, () => {
|
|
355
359
|
this.setPointerCapture(e.originalEvent.pointerId);
|
|
356
360
|
});
|
|
357
361
|
})
|
|
358
|
-
.on('pointermove', function(e) {
|
|
362
|
+
.on('pointermove', function (e) {
|
|
359
363
|
pMove(e.originalEvent.clientX);
|
|
360
364
|
})
|
|
361
|
-
.on('pointerup', async function(e) {
|
|
365
|
+
.on('pointerup', async function (e) {
|
|
362
366
|
await pEnd(() => {
|
|
363
367
|
this.releasePointerCapture(e.originalEvent.pointerId);
|
|
364
368
|
});
|
|
@@ -380,23 +384,23 @@ Banner.prototype.bindEvent = function(){
|
|
|
380
384
|
$inner.on('transitionend', () => {
|
|
381
385
|
$inner.css('transition', 'none');
|
|
382
386
|
})
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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
|
+
}
|
|
391
395
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
396
|
+
const $t = self.$inner.children().eq(self.index + 1);
|
|
397
|
+
self.options.click($t, self.options.list[self.index], self.index);
|
|
398
|
+
});
|
|
395
399
|
}
|
|
396
400
|
|
|
397
401
|
Banner.prototype.setTranslate = function (transX) {
|
|
398
402
|
this.currentTranslate = transX;
|
|
399
|
-
this.$inner.css('transform'
|
|
403
|
+
this.$inner.css('transform', `translateX(${this.currentTranslate}px)`);
|
|
400
404
|
}
|
|
401
405
|
|
|
402
406
|
/**
|
|
@@ -420,7 +424,7 @@ Banner.prototype.normalizeTranslate = async function () {
|
|
|
420
424
|
* 加载所有背景图片,将data-background-url属性设置为背景图片
|
|
421
425
|
*/
|
|
422
426
|
Banner.prototype.loadAllBackgrounds = function () {
|
|
423
|
-
this.$inner.children().each(function() {
|
|
427
|
+
this.$inner.children().each(function () {
|
|
424
428
|
$(this).css('background-image', `url(${$(this).attr('data-background-url')})`)
|
|
425
429
|
});
|
|
426
430
|
// console.log('banner images loaded');
|
package/components/list/list.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getEnv } from "../config";
|
|
2
|
+
|
|
3
|
+
let $ = null;
|
|
4
|
+
|
|
2
5
|
// 默认配置
|
|
3
6
|
const DEFAULTS = {
|
|
4
7
|
itemHeight: 50, // 单条数据高度
|
|
@@ -14,6 +17,8 @@ const DEFAULTS = {
|
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
export function List(options = {}) {
|
|
20
|
+
$ = getEnv().$;
|
|
21
|
+
|
|
17
22
|
this.options = Object.assign({}, DEFAULTS, options);
|
|
18
23
|
// 标记是否有更新元素用的回调函数
|
|
19
24
|
this.hasUpdateItem = options.updateItem && (options.updateItem.constructor === Function) ? true : false;
|
|
@@ -604,7 +604,7 @@ Waterfall.prototype.updateCard = function (data) {
|
|
|
604
604
|
|
|
605
605
|
const $node = this.activeNodes.get(dataId);
|
|
606
606
|
const height = $node.height();
|
|
607
|
-
|
|
607
|
+
|
|
608
608
|
// 重新计算该数据所在列的卡片位置
|
|
609
609
|
let needUpdate = false
|
|
610
610
|
const columnItems = this.columnItems;
|
|
@@ -619,9 +619,8 @@ Waterfall.prototype.updateCard = function (data) {
|
|
|
619
619
|
bool = true
|
|
620
620
|
const oldHeight = row.bottom - row.top;
|
|
621
621
|
|
|
622
|
-
console.log('Waterfall: updateCard oldHeight', oldHeight);
|
|
623
622
|
minus = height - oldHeight;
|
|
624
|
-
|
|
623
|
+
|
|
625
624
|
if (minus === 0) {
|
|
626
625
|
// 找到了原节点数据,对比后没有变更 那么直接退出
|
|
627
626
|
return;
|