|
@@ -129,19 +129,26 @@ export class CanvasPlayer extends Mitt {
|
|
|
const scrollY = event.target.scrollTop;
|
|
|
|
|
|
deltaY = scrollY - lastKnownScrollPosition;
|
|
|
- console.log("deltaY", deltaY);
|
|
|
+
|
|
|
+ const clip = Array.from(this.clips).find(
|
|
|
+ (item) => item.id === this.currentType
|
|
|
+ );
|
|
|
+ const deltaHeight = clip.total * 100 - window.innerHeight;
|
|
|
+ const prcess = scrollY / deltaHeight;
|
|
|
+ const frame = Math.floor(clip.total * prcess);
|
|
|
+ this.currentFrame = frame;
|
|
|
+ this.reDraw(this.currentFrame, this.currentType);
|
|
|
// this.watchScroll(event);
|
|
|
}
|
|
|
watchScroll(event) {
|
|
|
if (this.canScroll) {
|
|
|
+ if (this.currentFrame < 0) {
|
|
|
+ this.currentFrame = 0;
|
|
|
+ }
|
|
|
if (event.deltaY > 0) {
|
|
|
- this.currentFrame < 1
|
|
|
- ? (this.currentFrame = 1)
|
|
|
- : this.autoIncrement(true);
|
|
|
+ this.autoIncrement(true);
|
|
|
} else {
|
|
|
- this.currentFrame < 1
|
|
|
- ? (this.currentFrame = 1)
|
|
|
- : this.autoIncrement(false);
|
|
|
+ this.autoIncrement(false);
|
|
|
}
|
|
|
}
|
|
|
this.initClipScrollheight();
|
|
@@ -162,7 +169,7 @@ export class CanvasPlayer extends Mitt {
|
|
|
}
|
|
|
|
|
|
autoIncrement(na = true) {
|
|
|
- if (this.currentFrame > 0) {
|
|
|
+ if (this.currentFrame >= 0) {
|
|
|
const clip = Array.from(this.clips).find(
|
|
|
(item) => item.id === this.currentType
|
|
|
);
|
|
@@ -171,14 +178,14 @@ export class CanvasPlayer extends Mitt {
|
|
|
return;
|
|
|
}
|
|
|
if (na) {
|
|
|
- this.currentFrame++;
|
|
|
+ this.currentFrame += 1;
|
|
|
// console.log("111", this.currentFrame);
|
|
|
if (this.currentFrame === clip.total) {
|
|
|
this.emit("scroll-next");
|
|
|
}
|
|
|
this.reDraw(this.currentFrame, this.currentType);
|
|
|
} else {
|
|
|
- this.currentFrame--;
|
|
|
+ this.currentFrame -= 1;
|
|
|
// console.log("222", this.currentFrame);
|
|
|
if (this.currentFrame === 0) {
|
|
|
this.emit("scroll-prev");
|
|
@@ -222,7 +229,7 @@ export class CanvasPlayer extends Mitt {
|
|
|
}
|
|
|
initFirstFrame() {
|
|
|
if (this.currentType) {
|
|
|
- console.log("initFirstFrame", initFirstFrame);
|
|
|
+ console.log("initFirstFrame");
|
|
|
const frameItem = this.frames.find(
|
|
|
(item) => item.id == this.currentType && item.index == 1
|
|
|
);
|