|
@@ -62,9 +62,7 @@ export class CanvasPlayer extends Mitt {
|
|
|
(pre, current) => pre + current["total"],
|
|
|
0
|
|
|
);
|
|
|
- console.log("total", total);
|
|
|
Array.from(this.setting).forEach((item, framekey) => {
|
|
|
- console.log("item", item, framekey);
|
|
|
const base = [];
|
|
|
const clip = {
|
|
|
id: item.sectionType,
|
|
@@ -117,30 +115,40 @@ export class CanvasPlayer extends Mitt {
|
|
|
enableScroll(type = 0) {
|
|
|
this.canScroll = true;
|
|
|
this.currentType = type;
|
|
|
- // this.initFirstFrame();
|
|
|
+ this.initFirstFrame();
|
|
|
}
|
|
|
unEnableScroll() {
|
|
|
this.canScroll = false;
|
|
|
}
|
|
|
manualScroll(event, type) {
|
|
|
+ if (!this.canScroll) {
|
|
|
+ this.enableScroll(type);
|
|
|
+ }
|
|
|
let lastKnownScrollPosition = 0;
|
|
|
let deltaY = 0;
|
|
|
const scrollY = event.target.scrollTop;
|
|
|
- this.enableScroll(type);
|
|
|
+
|
|
|
deltaY = scrollY - lastKnownScrollPosition;
|
|
|
|
|
|
+ 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();
|
|
@@ -161,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
|
|
|
);
|
|
@@ -170,12 +178,18 @@ export class CanvasPlayer extends Mitt {
|
|
|
return;
|
|
|
}
|
|
|
if (na) {
|
|
|
- console.log("1111");
|
|
|
- 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 {
|
|
|
- console.log("222");
|
|
|
- this.currentFrame--;
|
|
|
+ this.currentFrame -= 1;
|
|
|
+ // console.log("222", this.currentFrame);
|
|
|
+ if (this.currentFrame === 0) {
|
|
|
+ this.emit("scroll-prev");
|
|
|
+ }
|
|
|
this.reDraw(this.currentFrame, this.currentType);
|
|
|
}
|
|
|
const process = Number(this.currentFrame / clip.total) * 100;
|
|
@@ -215,6 +229,7 @@ export class CanvasPlayer extends Mitt {
|
|
|
}
|
|
|
initFirstFrame() {
|
|
|
if (this.currentType) {
|
|
|
+ console.log("initFirstFrame");
|
|
|
const frameItem = this.frames.find(
|
|
|
(item) => item.id == this.currentType && item.index == 1
|
|
|
);
|