tencent.jquery.pix.component 1.0.63-beta.4 → 1.0.63-beta.6
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,3 +1,4 @@
|
|
|
1
|
+
import "./waterfall.scss"
|
|
1
2
|
import { getEnv } from "../config.js";
|
|
2
3
|
import { remToPx } from "../../utils/utils.js";
|
|
3
4
|
|
|
@@ -19,7 +20,10 @@ const DEFAULTS = {
|
|
|
19
20
|
// 传入 $node, data, index
|
|
20
21
|
updateItem: null, // 元素更新时的回调函数
|
|
21
22
|
onscroll: null, // 滚动事件回调函数
|
|
22
|
-
shouldOccupySpace: null // 是否是静态数据的回调函数,静态数据能够占用元素
|
|
23
|
+
shouldOccupySpace: null, // 是否是静态数据的回调函数,静态数据能够占用元素
|
|
24
|
+
showLoading: null, // 展示loading的回调函数 params:$node
|
|
25
|
+
hideLoading: null, // 隐藏loading的回调函数
|
|
26
|
+
createLoading: null, // 创建loading的回调函数
|
|
23
27
|
};
|
|
24
28
|
|
|
25
29
|
export function Waterfall(optionsInput = {}) {
|
|
@@ -36,6 +40,8 @@ export function Waterfall(optionsInput = {}) {
|
|
|
36
40
|
this.nextDataId = 0; // 下一个数据ID
|
|
37
41
|
this.renderedDataIds = new Set(); // 已渲染的数据ID集合
|
|
38
42
|
|
|
43
|
+
this.$loadingNode = null;
|
|
44
|
+
|
|
39
45
|
|
|
40
46
|
// 间隔字符串转数字
|
|
41
47
|
if (options.columnGap.constructor === String) {
|
|
@@ -125,14 +131,24 @@ Waterfall.prototype.init = function () {
|
|
|
125
131
|
this.allReadyNodes = new Map(); // 所有节点(索引 -> DOM)
|
|
126
132
|
this.renderIndex = 0; // 渲染索引(保留兼容性)
|
|
127
133
|
|
|
128
|
-
|
|
129
|
-
|
|
130
134
|
$container.html(`
|
|
131
135
|
<div class="waterfall-list-scroll" style="">
|
|
132
136
|
<div class="waterfall-list-viewport"></div>
|
|
133
137
|
</div>
|
|
134
138
|
`);
|
|
135
139
|
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
// 如果有定义loading函数 那么创建一个loading节点元素
|
|
143
|
+
if (options.createLoading) {
|
|
144
|
+
this.$loadingNode = $(
|
|
145
|
+
`<div class="waterfall-loading" style="transform: translate(0px, -99999px)"></div>`
|
|
146
|
+
);
|
|
147
|
+
$container.find('.waterfall-list-viewport').append(this.$loadingNode);
|
|
148
|
+
|
|
149
|
+
options.createLoading(this.$loadingNode);
|
|
150
|
+
}
|
|
151
|
+
|
|
136
152
|
// 绑定滚动事件(节流处理)
|
|
137
153
|
$container.off().on('scroll', function () {
|
|
138
154
|
self.scrollTop = $(this).scrollTop();
|
|
@@ -681,6 +697,49 @@ Waterfall.prototype.updatePointCards = function () {
|
|
|
681
697
|
}
|
|
682
698
|
}
|
|
683
699
|
|
|
700
|
+
// 展示loading的回调函数
|
|
701
|
+
Waterfall.prototype.showLoading = function (callback = null) {
|
|
702
|
+
const options = this.options;
|
|
703
|
+
const $container = $(options.container);
|
|
704
|
+
let $node = null
|
|
705
|
+
if (this.$loadingNode) {
|
|
706
|
+
let loadingTop = this.getMaxHeight() + options.rowGap
|
|
707
|
+
let h = loadingTop + this.$loadingNode.height() + options.marginBottom
|
|
708
|
+
|
|
709
|
+
this.$loadingNode.css('transform', `translate(0px,${loadingTop}px)`);
|
|
710
|
+
$(options.container).find('.waterfall-list-scroll').css('height', h + 'px');
|
|
711
|
+
|
|
712
|
+
$node = this.$loadingNode
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (callback) callback($node)
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// 隐藏loading的回调函数
|
|
719
|
+
Waterfall.prototype.hideLoading = function (callback = null) {
|
|
720
|
+
const options = this.options;
|
|
721
|
+
const $container = $(options.container);
|
|
722
|
+
let $node = null
|
|
723
|
+
if (this.$loadingNode) {
|
|
724
|
+
let h1 = this.getMaxHeight() + options.marginBottom
|
|
725
|
+
this.$loadingNode.css('transform', `translate(0px,-99999px)`);
|
|
726
|
+
//如果要设置高度,那么这里判断一下当前是否正在做updata 一般这里被调用时,数据已经读到,在updata的同一时间调用了该函数
|
|
727
|
+
// 如果两个时刻高度是一致的 那么数据就是一致的 这里重新设置回来高度即可
|
|
728
|
+
window.requestAnimationFrame(() => {
|
|
729
|
+
let h2 = this.getMaxHeight() + options.marginBottom
|
|
730
|
+
if (h1 === h2) {
|
|
731
|
+
const $scroll = $(options.container).find('.waterfall-list-scroll')
|
|
732
|
+
const h = $scroll.height()
|
|
733
|
+
if (h !== h1) {
|
|
734
|
+
$scroll.css('height', h1 + 'px');
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
})
|
|
738
|
+
$node = this.$loadingNode
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (callback) callback($node)
|
|
742
|
+
}
|
|
684
743
|
|
|
685
744
|
function createDefaultRow({ top, left }) {
|
|
686
745
|
return {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.waterfall-list-scroll {
|
|
2
|
+
height: 100%;
|
|
3
|
+
.waterfall-loading {
|
|
4
|
+
position: absolute;
|
|
5
|
+
width: 100%;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: center;
|
|
8
|
+
}
|
|
9
|
+
.waterfall-item {
|
|
10
|
+
flex: 1;
|
|
11
|
+
flex-shrink: 1;
|
|
12
|
+
flex-grow: 1;
|
|
13
|
+
flex-basis: 0;
|
|
14
|
+
width: 100%;
|
|
15
|
+
position: absolute;
|
|
16
|
+
}
|
|
17
|
+
}
|