|
@@ -1,5 +1,5 @@
|
|
import { isMobile } from "./isMoblie";
|
|
import { isMobile } from "./isMoblie";
|
|
-import { throttle, debounce, clamp, aspectFit } from "./fn";
|
|
|
|
|
|
+import { throttle, debounce, clamp, cover, contain } from "./fn";
|
|
import gsap from "gsap";
|
|
import gsap from "gsap";
|
|
import mitt from "mitt";
|
|
import mitt from "mitt";
|
|
class Mitt {
|
|
class Mitt {
|
|
@@ -57,8 +57,10 @@ export class CanvasPlayer extends Mitt {
|
|
});
|
|
});
|
|
this.vw = this.canvas.width = window.innerWidth;
|
|
this.vw = this.canvas.width = window.innerWidth;
|
|
this.vh = this.canvas.height = window.innerHeight;
|
|
this.vh = this.canvas.height = window.innerHeight;
|
|
- this.imageW = isMobile() ? 1170 : 1920;
|
|
|
|
- this.imageH = isMobile() ? 2532 : 1080;
|
|
|
|
|
|
+ // this.imageW = isMobile() ? 1170 : 1920;
|
|
|
|
+ // this.imageH = isMobile() ? 2532 : 1080;
|
|
|
|
+ this.imageW = isMobile() ? 750 : 1920;
|
|
|
|
+ this.imageH = isMobile() ? 1623 : 1080;
|
|
this.loadEvent();
|
|
this.loadEvent();
|
|
}
|
|
}
|
|
loadImage(url) {
|
|
loadImage(url) {
|
|
@@ -442,11 +444,11 @@ export class CanvasPlayer extends Mitt {
|
|
if (frameItem && frameItem.index <= frameItem.total) {
|
|
if (frameItem && frameItem.index <= frameItem.total) {
|
|
this.context.clearRect(0, 0, this.vw, this.vh);
|
|
this.context.clearRect(0, 0, this.vw, this.vh);
|
|
if (isMobile()) {
|
|
if (isMobile()) {
|
|
- var hRatio = this.vw / this.imageW;
|
|
|
|
- var vRatio = this.vh / this.imageH;
|
|
|
|
- var ratio = Math.min(hRatio, vRatio);
|
|
|
|
- var centerShift_x = (this.vw - this.imageW * ratio) / 2;
|
|
|
|
- var centerShift_y = (this.vh - this.imageH * ratio) / 2;
|
|
|
|
|
|
+ // var hRatio = this.vw / this.imageW;
|
|
|
|
+ // var vRatio = this.vh / this.imageH;
|
|
|
|
+ // var ratio = Math.min(hRatio, vRatio);
|
|
|
|
+ // var centerShift_x = (this.vw - this.imageW * ratio) / 2;
|
|
|
|
+ // var centerShift_y = (this.vh - this.imageH * ratio) / 2;
|
|
// this.context.drawImage(
|
|
// this.context.drawImage(
|
|
// frameItem.image,
|
|
// frameItem.image,
|
|
// 0,
|
|
// 0,
|
|
@@ -458,11 +460,26 @@ export class CanvasPlayer extends Mitt {
|
|
// this.imageW * ratio,
|
|
// this.imageW * ratio,
|
|
// this.imageH * ratio
|
|
// this.imageH * ratio
|
|
// );
|
|
// );
|
|
- var ratio =
|
|
|
|
- frameItem.image.naturalWidth / frameItem.image.naturalHeight;
|
|
|
|
- var width = this.vw;
|
|
|
|
- var height = width / ratio;
|
|
|
|
- this.context.drawImage(frameItem.image, 0, 0, width, height);
|
|
|
|
|
|
+
|
|
|
|
+ // var ratio =
|
|
|
|
+ // frameItem.image.naturalWidth / frameItem.image.naturalHeight;
|
|
|
|
+ // var width = this.vw;
|
|
|
|
+ // var height = width / ratio;
|
|
|
|
+
|
|
|
|
+ const { offsetX, offsetY, width, height } = cover(
|
|
|
|
+ this.vw,
|
|
|
|
+ this.vh,
|
|
|
|
+ this.imageW,
|
|
|
|
+ this.imageH
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ this.context.drawImage(
|
|
|
|
+ frameItem.image,
|
|
|
|
+ offsetX,
|
|
|
|
+ offsetY,
|
|
|
|
+ width,
|
|
|
|
+ height
|
|
|
|
+ );
|
|
} else {
|
|
} else {
|
|
this.context.drawImage(frameItem.image, 0, 0, this.vw, this.vh);
|
|
this.context.drawImage(frameItem.image, 0, 0, this.vw, this.vh);
|
|
}
|
|
}
|