|
@@ -1,4 +1,5 @@
|
|
|
import { isMobile } from "./isMoblie";
|
|
|
+import { throttle, debounce } from "./fn";
|
|
|
import gsap from "gsap";
|
|
|
import mitt from "mitt";
|
|
|
class Mitt {
|
|
@@ -22,6 +23,8 @@ export class CanvasPlayer extends Mitt {
|
|
|
this.currentType = 0;
|
|
|
this.frames = [];
|
|
|
this.clips = [];
|
|
|
+ this.tmpDisArr = [];
|
|
|
+ this.tmpDis = "";
|
|
|
this.canScroll = false;
|
|
|
this.resize = this.resize.bind(this);
|
|
|
this.watchScroll = this.watchScroll.bind(this);
|
|
@@ -123,6 +126,7 @@ export class CanvasPlayer extends Mitt {
|
|
|
manualScroll(event, type) {
|
|
|
if (!this.canScroll) {
|
|
|
this.enableScroll(type);
|
|
|
+ this.initFirstFrame();
|
|
|
}
|
|
|
let lastKnownScrollPosition = 0;
|
|
|
let deltaY = 0;
|
|
@@ -135,8 +139,19 @@ export class CanvasPlayer extends Mitt {
|
|
|
);
|
|
|
const deltaHeight = clip.total * 100 - window.innerHeight;
|
|
|
const prcess = scrollY / deltaHeight;
|
|
|
- const frame = Math.floor(clip.total * prcess);
|
|
|
+ const frame = Math.round(clip.total * prcess);
|
|
|
this.currentFrame = frame;
|
|
|
+ // if (frame === 0) {
|
|
|
+ // const toPrev = debounce(() => {
|
|
|
+ // console.log("frame", frame);
|
|
|
+ // this.emit("scroll-prev");
|
|
|
+ // this.resetClipScrollTop();
|
|
|
+ // }, 3000);
|
|
|
+ // toPrev();
|
|
|
+ // }
|
|
|
+ // if (frame === clip.total) {
|
|
|
+ // this.emit("scroll-next");
|
|
|
+ // }
|
|
|
this.reDraw(this.currentFrame, this.currentType);
|
|
|
// this.watchScroll(event);
|
|
|
}
|
|
@@ -146,9 +161,9 @@ export class CanvasPlayer extends Mitt {
|
|
|
this.currentFrame = 0;
|
|
|
}
|
|
|
if (event.deltaY > 0) {
|
|
|
- this.autoIncrement(true);
|
|
|
+ // this.autoIncrement(true);
|
|
|
} else {
|
|
|
- this.autoIncrement(false);
|
|
|
+ // this.autoIncrement(false);
|
|
|
}
|
|
|
}
|
|
|
this.initClipScrollheight();
|
|
@@ -156,6 +171,7 @@ export class CanvasPlayer extends Mitt {
|
|
|
easeOutCubic(x) {
|
|
|
return 1 - Math.pow(1 - x, 3);
|
|
|
}
|
|
|
+ currentScollSafeDistance() {}
|
|
|
initClipScrollheight() {
|
|
|
if (this.currentType) {
|
|
|
const bar = document.querySelector(`.scroll-bar-${this.currentType}`);
|
|
@@ -167,6 +183,12 @@ export class CanvasPlayer extends Mitt {
|
|
|
bar.style.height = `${deltaHeight}px`;
|
|
|
}
|
|
|
}
|
|
|
+ resetClipScrollTop() {
|
|
|
+ if (this.currentType) {
|
|
|
+ const bar = document.querySelector(`.scroll-bar-${this.currentType}`);
|
|
|
+ bar.style.scrollTop = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
autoIncrement(na = true) {
|
|
|
if (this.currentFrame >= 0) {
|