lyb-pixi-js 1.8.9 → 1.8.11

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.
@@ -70,10 +70,14 @@ export declare class LibPixiScrollContainerY extends LibPixiContainer {
70
70
  private _limitScrollRange;
71
71
  /** @description 更新滚动位置 */
72
72
  private _updateScrollbar;
73
+ /** @description 更新滚动条大小 */
74
+ private _updateScrollbarSize;
73
75
  /** @description 滚动条按下 */
74
76
  private _onScrollbarDragStart;
75
77
  /** @description 滚动条移动 */
76
78
  private _onScrollbarDragMove;
77
79
  /** @description 滚动条松开 */
78
80
  private _onScrollbarDragEnd;
81
+ /** @description 滚动结束一秒后隐藏滚动条 */
82
+ private _hideScrollbar;
79
83
  }
@@ -1,8 +1,8 @@
1
1
  import { Container } from "pixi.js";
2
+ import { gsap } from "gsap";
3
+ import { LibPixiRectangle } from "../Base/LibPixiRectangle";
2
4
  import { libPixiEvent } from "../../Utils/LibPixiEvent";
3
5
  import { LibPixiContainer } from "../Base/LibPixiContainer";
4
- import { LibPixiRectangle } from "../Base/LibPixiRectangle";
5
- import { gsap } from "gsap";
6
6
  /** @description 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
7
7
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollContainerY-Y 轴滚动容器
8
8
  */
@@ -41,13 +41,28 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
41
41
  this._scrollbar.x = width - (scrollbarRgiht || scrollbarWidth);
42
42
  this.addChild(this._scrollbar);
43
43
  this._scrollbar.visible = scrollbar;
44
- this._updateScrollbar();
44
+ this._scrollbar.alpha = 0;
45
+ this._updateScrollbarSize();
46
+ //是否已经离开滚动条
45
47
  libPixiEvent(this._scrollbar, "pointerdown", this._onScrollbarDragStart.bind(this));
48
+ libPixiEvent(this._scrollbar, "pointerenter", () => {
49
+ gsap.killTweensOf(this._scrollbar);
50
+ this._scrollbar.alpha = 1;
51
+ this._updateScrollbarSize();
52
+ });
53
+ libPixiEvent(this._scrollbar, "pointerleave", () => {
54
+ gsap.to(this._scrollbar, {
55
+ duration: 0.5,
56
+ alpha: 0,
57
+ delay: 1,
58
+ });
59
+ });
46
60
  // 添加事件监听
47
61
  this.eventMode = "static";
48
62
  this.on("pointerdown", this._onDragStart, this);
49
63
  libPixiEvent(this, "pointerdown", (event) => {
50
64
  this._onDragStart(event);
65
+ this._updateScrollbarSize();
51
66
  });
52
67
  libPixiEvent(this, "pointermove", (event) => {
53
68
  this._onScrollbarDragMove(event);
@@ -59,6 +74,7 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
59
74
  });
60
75
  libPixiEvent(this, "wheel", (event) => {
61
76
  this._onWheelScroll(event);
77
+ this._updateScrollbarSize();
62
78
  });
63
79
  libPixiEvent(this, "pointerupoutside", () => {
64
80
  this._onDragEnd();
@@ -75,6 +91,7 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
75
91
  this._maskGraphics.drawRect(0, 0, width, height);
76
92
  this._maskGraphics.endFill();
77
93
  this.setSize(width, height);
94
+ this._scrollbar.x = width - 50;
78
95
  }
79
96
  /** @description 返回顶部 */
80
97
  scrollToTop() {
@@ -103,8 +120,8 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
103
120
  const position = event.getLocalPosition(this);
104
121
  const newPosition = position.y - this._startY;
105
122
  this._content.y = newPosition;
123
+ this._updateScrollbar();
106
124
  }
107
- this._updateScrollbar();
108
125
  }
109
126
  /** @description 拖动结束 */
110
127
  _onDragEnd() {
@@ -122,6 +139,11 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
122
139
  this._velocity = 0;
123
140
  }
124
141
  this._limitScrollRange();
142
+ gsap.to(this._scrollbar, {
143
+ duration: 0.5,
144
+ alpha: 0,
145
+ delay: 0.25,
146
+ });
125
147
  }
126
148
  /** @description 滚轮滚动 */
127
149
  _onWheelScroll(event) {
@@ -144,6 +166,9 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
144
166
  onUpdate: () => {
145
167
  this._updateScrollbar();
146
168
  },
169
+ onComplete: () => {
170
+ this._hideScrollbar();
171
+ },
147
172
  });
148
173
  }
149
174
  /** @description 惯性动画 */
@@ -156,6 +181,9 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
156
181
  this._limitScrollRange();
157
182
  this._updateScrollbar();
158
183
  },
184
+ onComplete: () => {
185
+ this._hideScrollbar();
186
+ },
159
187
  });
160
188
  }
161
189
  /** @description 限制滚动范围 */
@@ -169,6 +197,9 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
169
197
  onUpdate: () => {
170
198
  this._updateScrollbar();
171
199
  },
200
+ onComplete: () => {
201
+ this._hideScrollbar();
202
+ },
172
203
  });
173
204
  }
174
205
  // 如果滚动距离大于内容高度减去遮罩高度
@@ -184,6 +215,9 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
184
215
  onUpdate: () => {
185
216
  this._updateScrollbar();
186
217
  },
218
+ onComplete: () => {
219
+ this._hideScrollbar();
220
+ },
187
221
  });
188
222
  }
189
223
  // 否则静止不动
@@ -194,29 +228,36 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
194
228
  onUpdate: () => {
195
229
  this._updateScrollbar();
196
230
  },
231
+ onComplete: () => {
232
+ this._hideScrollbar();
233
+ },
197
234
  });
198
235
  }
199
236
  }
200
237
  }
201
238
  /** @description 更新滚动位置 */
202
239
  _updateScrollbar() {
240
+ this._scrollbar.alpha = 1;
241
+ gsap.killTweensOf(this._scrollbar);
203
242
  const viewHeight = this._maskGraphics.height;
204
243
  const contentHeight = this._content.height;
205
- if (contentHeight <= viewHeight) {
206
- this._scrollbar.visible = false;
207
- return;
208
- }
209
- this._scrollbar.visible = true;
210
244
  const ratio = viewHeight / contentHeight;
211
245
  const barHeight = viewHeight * ratio;
212
246
  const maxScrollY = contentHeight - viewHeight;
213
247
  const scrollY = Math.min(Math.max(-this._content.y, 0), maxScrollY);
214
248
  const barY = (scrollY / maxScrollY) * (viewHeight - barHeight);
249
+ this._scrollbar.y = barY;
250
+ }
251
+ /** @description 更新滚动条大小 */
252
+ _updateScrollbarSize() {
253
+ const viewHeight = this._maskGraphics.height;
254
+ const contentHeight = this._content.height;
255
+ const ratio = viewHeight / contentHeight;
256
+ const barHeight = viewHeight * ratio;
215
257
  this._scrollbar.clear();
216
258
  this._scrollbar.beginFill(this._scrollbarColor);
217
259
  this._scrollbar.drawRect(0, 0, 10, barHeight);
218
260
  this._scrollbar.endFill();
219
- this._scrollbar.y = barY;
220
261
  }
221
262
  /** @description 滚动条按下 */
222
263
  _onScrollbarDragStart(event) {
@@ -246,4 +287,12 @@ export class LibPixiScrollContainerY extends LibPixiContainer {
246
287
  event.stopPropagation();
247
288
  this._scrollbarDragging = false;
248
289
  }
290
+ /** @description 滚动结束一秒后隐藏滚动条 */
291
+ _hideScrollbar() {
292
+ gsap.to(this._scrollbar, {
293
+ duration: 0.5,
294
+ alpha: 0,
295
+ delay: 0.25,
296
+ });
297
+ }
249
298
  }
package/lyb-pixi.js CHANGED
@@ -49292,16 +49292,30 @@ void main(void)\r
49292
49292
  this._scrollbar.x = width - (scrollbarRgiht || scrollbarWidth);
49293
49293
  this.addChild(this._scrollbar);
49294
49294
  this._scrollbar.visible = scrollbar;
49295
- this._updateScrollbar();
49295
+ this._scrollbar.alpha = 0;
49296
+ this._updateScrollbarSize();
49296
49297
  libPixiEvent(
49297
49298
  this._scrollbar,
49298
49299
  "pointerdown",
49299
49300
  this._onScrollbarDragStart.bind(this)
49300
49301
  );
49302
+ libPixiEvent(this._scrollbar, "pointerenter", () => {
49303
+ gsapWithCSS.killTweensOf(this._scrollbar);
49304
+ this._scrollbar.alpha = 1;
49305
+ this._updateScrollbarSize();
49306
+ });
49307
+ libPixiEvent(this._scrollbar, "pointerleave", () => {
49308
+ gsapWithCSS.to(this._scrollbar, {
49309
+ duration: 0.5,
49310
+ alpha: 0,
49311
+ delay: 1
49312
+ });
49313
+ });
49301
49314
  this.eventMode = "static";
49302
49315
  this.on("pointerdown", this._onDragStart, this);
49303
49316
  libPixiEvent(this, "pointerdown", (event) => {
49304
49317
  this._onDragStart(event);
49318
+ this._updateScrollbarSize();
49305
49319
  });
49306
49320
  libPixiEvent(this, "pointermove", (event) => {
49307
49321
  this._onScrollbarDragMove(event);
@@ -49313,6 +49327,7 @@ void main(void)\r
49313
49327
  });
49314
49328
  libPixiEvent(this, "wheel", (event) => {
49315
49329
  this._onWheelScroll(event);
49330
+ this._updateScrollbarSize();
49316
49331
  });
49317
49332
  libPixiEvent(this, "pointerupoutside", () => {
49318
49333
  this._onDragEnd();
@@ -49328,6 +49343,7 @@ void main(void)\r
49328
49343
  this._maskGraphics.drawRect(0, 0, width, height);
49329
49344
  this._maskGraphics.endFill();
49330
49345
  this.setSize(width, height);
49346
+ this._scrollbar.x = width - 50;
49331
49347
  }
49332
49348
  /** @description 返回顶部 */
49333
49349
  scrollToTop() {
@@ -49356,8 +49372,8 @@ void main(void)\r
49356
49372
  const position = event.getLocalPosition(this);
49357
49373
  const newPosition = position.y - this._startY;
49358
49374
  this._content.y = newPosition;
49375
+ this._updateScrollbar();
49359
49376
  }
49360
- this._updateScrollbar();
49361
49377
  }
49362
49378
  /** @description 拖动结束 */
49363
49379
  _onDragEnd() {
@@ -49372,6 +49388,11 @@ void main(void)\r
49372
49388
  this._velocity = 0;
49373
49389
  }
49374
49390
  this._limitScrollRange();
49391
+ gsapWithCSS.to(this._scrollbar, {
49392
+ duration: 0.5,
49393
+ alpha: 0,
49394
+ delay: 0.25
49395
+ });
49375
49396
  }
49376
49397
  /** @description 滚轮滚动 */
49377
49398
  _onWheelScroll(event) {
@@ -49389,6 +49410,9 @@ void main(void)\r
49389
49410
  y: y2,
49390
49411
  onUpdate: () => {
49391
49412
  this._updateScrollbar();
49413
+ },
49414
+ onComplete: () => {
49415
+ this._hideScrollbar();
49392
49416
  }
49393
49417
  });
49394
49418
  }
@@ -49401,6 +49425,9 @@ void main(void)\r
49401
49425
  onUpdate: () => {
49402
49426
  this._limitScrollRange();
49403
49427
  this._updateScrollbar();
49428
+ },
49429
+ onComplete: () => {
49430
+ this._hideScrollbar();
49404
49431
  }
49405
49432
  });
49406
49433
  }
@@ -49413,6 +49440,9 @@ void main(void)\r
49413
49440
  ease: "elastic.out",
49414
49441
  onUpdate: () => {
49415
49442
  this._updateScrollbar();
49443
+ },
49444
+ onComplete: () => {
49445
+ this._hideScrollbar();
49416
49446
  }
49417
49447
  });
49418
49448
  } else if (Math.abs(this._content.y) >= this._content.height - this._maskGraphics.height) {
@@ -49424,6 +49454,9 @@ void main(void)\r
49424
49454
  ease: "elastic.out",
49425
49455
  onUpdate: () => {
49426
49456
  this._updateScrollbar();
49457
+ },
49458
+ onComplete: () => {
49459
+ this._hideScrollbar();
49427
49460
  }
49428
49461
  });
49429
49462
  } else {
@@ -49432,6 +49465,9 @@ void main(void)\r
49432
49465
  y: 0,
49433
49466
  onUpdate: () => {
49434
49467
  this._updateScrollbar();
49468
+ },
49469
+ onComplete: () => {
49470
+ this._hideScrollbar();
49435
49471
  }
49436
49472
  });
49437
49473
  }
@@ -49439,23 +49475,27 @@ void main(void)\r
49439
49475
  }
49440
49476
  /** @description 更新滚动位置 */
49441
49477
  _updateScrollbar() {
49478
+ this._scrollbar.alpha = 1;
49479
+ gsapWithCSS.killTweensOf(this._scrollbar);
49442
49480
  const viewHeight = this._maskGraphics.height;
49443
49481
  const contentHeight = this._content.height;
49444
- if (contentHeight <= viewHeight) {
49445
- this._scrollbar.visible = false;
49446
- return;
49447
- }
49448
- this._scrollbar.visible = true;
49449
49482
  const ratio = viewHeight / contentHeight;
49450
49483
  const barHeight = viewHeight * ratio;
49451
49484
  const maxScrollY = contentHeight - viewHeight;
49452
49485
  const scrollY = Math.min(Math.max(-this._content.y, 0), maxScrollY);
49453
49486
  const barY = scrollY / maxScrollY * (viewHeight - barHeight);
49487
+ this._scrollbar.y = barY;
49488
+ }
49489
+ /** @description 更新滚动条大小 */
49490
+ _updateScrollbarSize() {
49491
+ const viewHeight = this._maskGraphics.height;
49492
+ const contentHeight = this._content.height;
49493
+ const ratio = viewHeight / contentHeight;
49494
+ const barHeight = viewHeight * ratio;
49454
49495
  this._scrollbar.clear();
49455
49496
  this._scrollbar.beginFill(this._scrollbarColor);
49456
49497
  this._scrollbar.drawRect(0, 0, 10, barHeight);
49457
49498
  this._scrollbar.endFill();
49458
- this._scrollbar.y = barY;
49459
49499
  }
49460
49500
  /** @description 滚动条按下 */
49461
49501
  _onScrollbarDragStart(event) {
@@ -49488,6 +49528,14 @@ void main(void)\r
49488
49528
  event.stopPropagation();
49489
49529
  this._scrollbarDragging = false;
49490
49530
  }
49531
+ /** @description 滚动结束一秒后隐藏滚动条 */
49532
+ _hideScrollbar() {
49533
+ gsapWithCSS.to(this._scrollbar, {
49534
+ duration: 0.5,
49535
+ alpha: 0,
49536
+ delay: 0.25
49537
+ });
49538
+ }
49491
49539
  }
49492
49540
  const LibJsLerp = (start, end, value) => {
49493
49541
  const t2 = Math.min(Math.max(value, 0), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-pixi-js",
3
- "version": "1.8.9",
3
+ "version": "1.8.11",
4
4
  "description": "自用Pixi.JS方法库",
5
5
  "license": "ISC",
6
6
  "exports": {