lyb-pixi-js 1.7.1 → 1.7.2
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,5 +1,5 @@
|
|
|
1
1
|
import { Container } from "pixi.js";
|
|
2
|
-
import { LibPixiContainer } from
|
|
2
|
+
import { LibPixiContainer } from '../Base/LibPixiContainer';
|
|
3
3
|
export interface LibPixiScrollContainerParams {
|
|
4
4
|
/** 宽度 */
|
|
5
5
|
width: number;
|
|
@@ -9,6 +9,8 @@ export interface LibPixiScrollContainerParams {
|
|
|
9
9
|
scrollContent: Container;
|
|
10
10
|
/** 底部内边距 */
|
|
11
11
|
bottomMargin?: number;
|
|
12
|
+
/** 滚动方向,vertical | horizontal,默认vertical */
|
|
13
|
+
direction?: "vertical" | "horizontal";
|
|
12
14
|
}
|
|
13
15
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
14
16
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainer-滚动容器
|
|
@@ -26,6 +28,8 @@ export declare class LibPixiScrollContainer extends LibPixiContainer {
|
|
|
26
28
|
private _scrollSpeed;
|
|
27
29
|
/** 是否处于拖动状态 */
|
|
28
30
|
private _isDragging;
|
|
31
|
+
/** 滚动方向 */
|
|
32
|
+
private _direction;
|
|
29
33
|
/** 滚动容器 */
|
|
30
34
|
_scrollContent: Container;
|
|
31
35
|
/** 遮罩 */
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Container, Graphics, Sprite, } from "pixi.js";
|
|
2
2
|
import { gsap } from "gsap";
|
|
3
|
-
import { LibPixiContainer } from
|
|
3
|
+
import { LibPixiContainer } from '../Base/LibPixiContainer';
|
|
4
4
|
/** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
5
5
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainer-滚动容器
|
|
6
6
|
*/
|
|
7
7
|
export class LibPixiScrollContainer extends LibPixiContainer {
|
|
8
8
|
constructor(params) {
|
|
9
|
+
var _a;
|
|
9
10
|
const { width, height, scrollContent, bottomMargin = 50 } = params;
|
|
10
11
|
super(width, height);
|
|
11
12
|
/** 开始位置 */
|
|
@@ -20,7 +21,10 @@ export class LibPixiScrollContainer extends LibPixiContainer {
|
|
|
20
21
|
this._scrollSpeed = 200;
|
|
21
22
|
/** 是否处于拖动状态 */
|
|
22
23
|
this._isDragging = false;
|
|
24
|
+
/** 滚动方向 */
|
|
25
|
+
this._direction = "vertical";
|
|
23
26
|
this._scrollContent = scrollContent;
|
|
27
|
+
this._direction = (_a = params.direction) !== null && _a !== void 0 ? _a : "vertical";
|
|
24
28
|
// 创建内容容器
|
|
25
29
|
this._content = new Container();
|
|
26
30
|
this.addChild(this._content);
|
|
@@ -73,7 +77,10 @@ export class LibPixiScrollContainer extends LibPixiContainer {
|
|
|
73
77
|
if (this._content.height <= this._maskGraphics.height)
|
|
74
78
|
return;
|
|
75
79
|
const position = event.getLocalPosition(this);
|
|
76
|
-
this._startY =
|
|
80
|
+
this._startY =
|
|
81
|
+
this._direction === "vertical"
|
|
82
|
+
? position.y - this._content.y
|
|
83
|
+
: position.x - this._content.x;
|
|
77
84
|
this._isDragging = true;
|
|
78
85
|
this._velocity = 0;
|
|
79
86
|
this._startTime = Date.now();
|
|
@@ -84,8 +91,15 @@ export class LibPixiScrollContainer extends LibPixiContainer {
|
|
|
84
91
|
_onDragMove(event) {
|
|
85
92
|
if (this._isDragging) {
|
|
86
93
|
const position = event.getLocalPosition(this);
|
|
87
|
-
const newPosition =
|
|
88
|
-
|
|
94
|
+
const newPosition = this._direction === "vertical"
|
|
95
|
+
? position.y - this._startY
|
|
96
|
+
: position.x - this._startY;
|
|
97
|
+
if (this._direction === "vertical") {
|
|
98
|
+
this._content.y = newPosition;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this._content.x = newPosition;
|
|
102
|
+
}
|
|
89
103
|
}
|
|
90
104
|
}
|
|
91
105
|
/** @description 拖动结束 */
|
|
@@ -106,61 +120,47 @@ export class LibPixiScrollContainer extends LibPixiContainer {
|
|
|
106
120
|
}
|
|
107
121
|
/** @description 滚轮滚动 */
|
|
108
122
|
_onWheelScroll(event) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
y = 0;
|
|
123
|
+
if (this._direction === "vertical") {
|
|
124
|
+
if (this._content.height <= this._maskGraphics.height)
|
|
125
|
+
return;
|
|
126
|
+
let y = this._content.y - event.deltaY * (this._scrollSpeed / 100);
|
|
127
|
+
y = Math.min(0, Math.max(y, -(this._content.height - this._maskGraphics.height)));
|
|
128
|
+
gsap.to(this._content, { duration: 0.25, ease: "power1.out", y });
|
|
116
129
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
else {
|
|
131
|
+
if (this._content.width <= this._maskGraphics.width)
|
|
132
|
+
return;
|
|
133
|
+
let x = this._content.x - event.deltaY * (this._scrollSpeed / 100);
|
|
134
|
+
x = Math.min(0, Math.max(x, -(this._content.width - this._maskGraphics.width)));
|
|
135
|
+
gsap.to(this._content, { duration: 0.25, ease: "power1.out", x });
|
|
120
136
|
}
|
|
121
|
-
gsap.to(this._content, {
|
|
122
|
-
duration: 0.25,
|
|
123
|
-
ease: "power1.out",
|
|
124
|
-
y,
|
|
125
|
-
});
|
|
126
137
|
}
|
|
127
138
|
/** @description 惯性动画 */
|
|
128
139
|
_applyInertia() {
|
|
129
|
-
gsap.to(this._content, {
|
|
130
|
-
y: this._content.y + this._velocity * 250
|
|
131
|
-
|
|
132
|
-
ease: "power1.out",
|
|
133
|
-
onUpdate: this._limitScrollRange.bind(this),
|
|
134
|
-
});
|
|
140
|
+
gsap.to(this._content, Object.assign({ duration: 0.5, ease: "power1.out", onUpdate: this._limitScrollRange.bind(this) }, (this._direction === "vertical"
|
|
141
|
+
? { y: this._content.y + this._velocity * 250 }
|
|
142
|
+
: { x: this._content.x + this._velocity * 250 })));
|
|
135
143
|
}
|
|
136
144
|
/** @description 限制滚动范围 */
|
|
137
145
|
_limitScrollRange() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
// 如果滚动距离大于内容高度减去遮罩高度
|
|
147
|
-
else if (Math.abs(this._content.y) >=
|
|
148
|
-
this._content.height - this._maskGraphics.height) {
|
|
149
|
-
// 如果内容高度大于遮罩高度,则滚动到底部
|
|
150
|
-
if (this._content.height > this._maskGraphics.height) {
|
|
146
|
+
if (this._direction === "vertical") {
|
|
147
|
+
if (this._content.y > 0) {
|
|
148
|
+
gsap.to(this._content, { duration: 0.75, y: 0, ease: "elastic.out" });
|
|
149
|
+
}
|
|
150
|
+
else if (Math.abs(this._content.y) >=
|
|
151
|
+
this._content.height - this._maskGraphics.height) {
|
|
151
152
|
const y = -(this._content.height - this._maskGraphics.height);
|
|
152
|
-
gsap.to(this._content, {
|
|
153
|
-
duration: 0.75,
|
|
154
|
-
y,
|
|
155
|
-
ease: "elastic.out",
|
|
156
|
-
});
|
|
153
|
+
gsap.to(this._content, { duration: 0.75, y, ease: "elastic.out" });
|
|
157
154
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
if (this._content.x > 0) {
|
|
158
|
+
gsap.to(this._content, { duration: 0.75, x: 0, ease: "elastic.out" });
|
|
159
|
+
}
|
|
160
|
+
else if (Math.abs(this._content.x) >=
|
|
161
|
+
this._content.width - this._maskGraphics.width) {
|
|
162
|
+
const x = -(this._content.width - this._maskGraphics.width);
|
|
163
|
+
gsap.to(this._content, { duration: 0.75, x, ease: "elastic.out" });
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}
|
package/README.md
CHANGED
|
@@ -146,8 +146,6 @@ app.stage.addChild(box);
|
|
|
146
146
|
|
|
147
147
|
\- [LibPixiPolygonDrawTool-多边形绘制](#LibPixiPolygonDrawTool-多边形绘制)
|
|
148
148
|
|
|
149
|
-
\- [LibPixiWatchProperty-对象属性监听](#LibPixiWatchProperty-对象属性监听)
|
|
150
|
-
|
|
151
149
|
## Base-基础
|
|
152
150
|
|
|
153
151
|
### LibPixiText-文本
|
|
@@ -1019,21 +1017,4 @@ $bus.on("play", () => {
|
|
|
1019
1017
|
|
|
1020
1018
|
```ts
|
|
1021
1019
|
new LibPixiPolygonDrawTool(app);
|
|
1022
|
-
```
|
|
1023
|
-
|
|
1024
|
-
### LibPixiWatchProperty-对象属性监听
|
|
1025
|
-
|
|
1026
|
-
> 内部通过 Ticker 每秒调用10次循环判断被监听的属性是否发生改变,当元素被销毁时自动销毁 Ticker,取决于是否传递了元素
|
|
1027
|
-
|
|
1028
|
-
```ts
|
|
1029
|
-
LibPixiWatchProperty(
|
|
1030
|
-
gameStore,
|
|
1031
|
-
["a", "b"],
|
|
1032
|
-
() => {
|
|
1033
|
-
warningContainer.visible = a;
|
|
1034
|
-
useBtn.eventMode = a || b ? "none" : "static";
|
|
1035
|
-
},
|
|
1036
|
-
this
|
|
1037
|
-
);
|
|
1038
|
-
```
|
|
1039
|
-
|
|
1020
|
+
```
|
package/lyb-pixi.js
CHANGED
|
@@ -49100,7 +49100,9 @@ void main(void)\r
|
|
|
49100
49100
|
this._startPosition = 0;
|
|
49101
49101
|
this._scrollSpeed = 200;
|
|
49102
49102
|
this._isDragging = false;
|
|
49103
|
+
this._direction = "vertical";
|
|
49103
49104
|
this._scrollContent = scrollContent;
|
|
49105
|
+
this._direction = params.direction ?? "vertical";
|
|
49104
49106
|
this._content = new Container();
|
|
49105
49107
|
this.addChild(this._content);
|
|
49106
49108
|
this._content.addChild(this._scrollContent);
|
|
@@ -49148,7 +49150,7 @@ void main(void)\r
|
|
|
49148
49150
|
if (this._content.height <= this._maskGraphics.height)
|
|
49149
49151
|
return;
|
|
49150
49152
|
const position = event.getLocalPosition(this);
|
|
49151
|
-
this._startY = position.y - this._content.y;
|
|
49153
|
+
this._startY = this._direction === "vertical" ? position.y - this._content.y : position.x - this._content.x;
|
|
49152
49154
|
this._isDragging = true;
|
|
49153
49155
|
this._velocity = 0;
|
|
49154
49156
|
this._startTime = Date.now();
|
|
@@ -49159,8 +49161,12 @@ void main(void)\r
|
|
|
49159
49161
|
_onDragMove(event) {
|
|
49160
49162
|
if (this._isDragging) {
|
|
49161
49163
|
const position = event.getLocalPosition(this);
|
|
49162
|
-
const newPosition = position.y - this._startY;
|
|
49163
|
-
this.
|
|
49164
|
+
const newPosition = this._direction === "vertical" ? position.y - this._startY : position.x - this._startY;
|
|
49165
|
+
if (this._direction === "vertical") {
|
|
49166
|
+
this._content.y = newPosition;
|
|
49167
|
+
} else {
|
|
49168
|
+
this._content.x = newPosition;
|
|
49169
|
+
}
|
|
49164
49170
|
}
|
|
49165
49171
|
}
|
|
49166
49172
|
/** @description 拖动结束 */
|
|
@@ -49178,50 +49184,50 @@ void main(void)\r
|
|
|
49178
49184
|
}
|
|
49179
49185
|
/** @description 滚轮滚动 */
|
|
49180
49186
|
_onWheelScroll(event) {
|
|
49181
|
-
if (this.
|
|
49182
|
-
|
|
49183
|
-
|
|
49184
|
-
|
|
49185
|
-
y2 =
|
|
49186
|
-
|
|
49187
|
-
|
|
49187
|
+
if (this._direction === "vertical") {
|
|
49188
|
+
if (this._content.height <= this._maskGraphics.height)
|
|
49189
|
+
return;
|
|
49190
|
+
let y2 = this._content.y - event.deltaY * (this._scrollSpeed / 100);
|
|
49191
|
+
y2 = Math.min(
|
|
49192
|
+
0,
|
|
49193
|
+
Math.max(y2, -(this._content.height - this._maskGraphics.height))
|
|
49194
|
+
);
|
|
49195
|
+
gsapWithCSS.to(this._content, { duration: 0.25, ease: "power1.out", y: y2 });
|
|
49196
|
+
} else {
|
|
49197
|
+
if (this._content.width <= this._maskGraphics.width)
|
|
49198
|
+
return;
|
|
49199
|
+
let x2 = this._content.x - event.deltaY * (this._scrollSpeed / 100);
|
|
49200
|
+
x2 = Math.min(
|
|
49201
|
+
0,
|
|
49202
|
+
Math.max(x2, -(this._content.width - this._maskGraphics.width))
|
|
49203
|
+
);
|
|
49204
|
+
gsapWithCSS.to(this._content, { duration: 0.25, ease: "power1.out", x: x2 });
|
|
49188
49205
|
}
|
|
49189
|
-
gsapWithCSS.to(this._content, {
|
|
49190
|
-
duration: 0.25,
|
|
49191
|
-
ease: "power1.out",
|
|
49192
|
-
y: y2
|
|
49193
|
-
});
|
|
49194
49206
|
}
|
|
49195
49207
|
/** @description 惯性动画 */
|
|
49196
49208
|
_applyInertia() {
|
|
49197
49209
|
gsapWithCSS.to(this._content, {
|
|
49198
|
-
y: this._content.y + this._velocity * 250,
|
|
49199
49210
|
duration: 0.5,
|
|
49200
49211
|
ease: "power1.out",
|
|
49201
|
-
onUpdate: this._limitScrollRange.bind(this)
|
|
49212
|
+
onUpdate: this._limitScrollRange.bind(this),
|
|
49213
|
+
...this._direction === "vertical" ? { y: this._content.y + this._velocity * 250 } : { x: this._content.x + this._velocity * 250 }
|
|
49202
49214
|
});
|
|
49203
49215
|
}
|
|
49204
49216
|
/** @description 限制滚动范围 */
|
|
49205
49217
|
_limitScrollRange() {
|
|
49206
|
-
if (this.
|
|
49207
|
-
|
|
49208
|
-
duration: 0.75,
|
|
49209
|
-
|
|
49210
|
-
ease: "elastic.out"
|
|
49211
|
-
});
|
|
49212
|
-
} else if (Math.abs(this._content.y) >= this._content.height - this._maskGraphics.height) {
|
|
49213
|
-
if (this._content.height > this._maskGraphics.height) {
|
|
49218
|
+
if (this._direction === "vertical") {
|
|
49219
|
+
if (this._content.y > 0) {
|
|
49220
|
+
gsapWithCSS.to(this._content, { duration: 0.75, y: 0, ease: "elastic.out" });
|
|
49221
|
+
} else if (Math.abs(this._content.y) >= this._content.height - this._maskGraphics.height) {
|
|
49214
49222
|
const y2 = -(this._content.height - this._maskGraphics.height);
|
|
49215
|
-
gsapWithCSS.to(this._content, {
|
|
49216
|
-
|
|
49217
|
-
|
|
49218
|
-
|
|
49219
|
-
});
|
|
49220
|
-
} else {
|
|
49221
|
-
|
|
49222
|
-
|
|
49223
|
-
y: 0
|
|
49224
|
-
});
|
|
49223
|
+
gsapWithCSS.to(this._content, { duration: 0.75, y: y2, ease: "elastic.out" });
|
|
49224
|
+
}
|
|
49225
|
+
} else {
|
|
49226
|
+
if (this._content.x > 0) {
|
|
49227
|
+
gsapWithCSS.to(this._content, { duration: 0.75, x: 0, ease: "elastic.out" });
|
|
49228
|
+
} else if (Math.abs(this._content.x) >= this._content.width - this._maskGraphics.width) {
|
|
49229
|
+
const x2 = -(this._content.width - this._maskGraphics.width);
|
|
49230
|
+
gsapWithCSS.to(this._content, { duration: 0.75, x: x2, ease: "elastic.out" });
|
|
49225
49231
|
}
|
|
49226
49232
|
}
|
|
49227
49233
|
}
|