|
@@ -2,7 +2,7 @@ import { Component, createRef } from "react";
|
|
|
import PropTypes from "prop-types";
|
|
|
import { gsap, ScrollTrigger } from "gsap/all";
|
|
|
import { css } from "@emotion/react";
|
|
|
-const isDebug = Number(import.meta.env.VITE_APP_SOURCE) === 1;
|
|
|
+const isDebug = Number(import.meta.env.VITE_APP_DEBUG) === 1;
|
|
|
console.log("isDebug", isDebug);
|
|
|
export default class Viewer extends Component {
|
|
|
constructor() {
|
|
@@ -37,6 +37,7 @@ export default class Viewer extends Component {
|
|
|
this.width = 1552;
|
|
|
this.height = 873;
|
|
|
this.justScrolled = false;
|
|
|
+ this.lastProgress = false;
|
|
|
this.isBelow = true;
|
|
|
this.isAbove = false;
|
|
|
}
|
|
@@ -80,7 +81,8 @@ export default class Viewer extends Component {
|
|
|
if (!this.exitTimeline && this.props.exitTween) {
|
|
|
this.initializeExitTween();
|
|
|
}
|
|
|
- ScrollTrigger.refresh();
|
|
|
+ ScrollTrigger.getAll().forEach((ST) => ST.refresh(true));
|
|
|
+ console.error("ScrollTrigger.getAll()", ScrollTrigger.getAll());
|
|
|
}
|
|
|
|
|
|
loadImage(index) {
|
|
@@ -140,17 +142,17 @@ export default class Viewer extends Component {
|
|
|
this.context.imageSmoothingQuality = "high";
|
|
|
}
|
|
|
initializeTimeline() {
|
|
|
- const openLoading = () => {
|
|
|
- gsap.to(this.loadingWrap.current, {
|
|
|
- autoAlpha: 1,
|
|
|
- });
|
|
|
- };
|
|
|
- const closeLoading = () => {
|
|
|
- gsap.to(this.loadingWrap.current, {
|
|
|
- autoAlpha: 0,
|
|
|
- });
|
|
|
- };
|
|
|
- closeLoading();
|
|
|
+ // const openLoading = () => {
|
|
|
+ // gsap.to(this.loadingWrap.current, {
|
|
|
+ // autoAlpha: 1,
|
|
|
+ // });
|
|
|
+ // };
|
|
|
+ // const closeLoading = () => {
|
|
|
+ // gsap.to(this.loadingWrap.current, {
|
|
|
+ // autoAlpha: 0,
|
|
|
+ // });
|
|
|
+ // };
|
|
|
+ // closeLoading();
|
|
|
this.timeline = gsap.timeline({
|
|
|
scrollTrigger: {
|
|
|
trigger: this.containerRef.current,
|
|
@@ -160,30 +162,40 @@ export default class Viewer extends Component {
|
|
|
end: "bottom bottom",
|
|
|
ease: "none",
|
|
|
markers: isDebug,
|
|
|
- onUpdate: function (n) {
|
|
|
+ onUpdate: (trigger) => {
|
|
|
//处理processloading
|
|
|
+ if (!this.lastProgress) {
|
|
|
+ this.lastProgress = trigger.progress;
|
|
|
+ // console.log("lastProgress", this.lastProgress);
|
|
|
+ } else {
|
|
|
+ if (this.lastProgress !== this.progress) {
|
|
|
+ this.justScrolled = true;
|
|
|
+ this.lastProgress = trigger.progress;
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
onScrubComplete: () => {
|
|
|
this.justScrolled = true;
|
|
|
},
|
|
|
onEnter: () => {
|
|
|
- closeLoading();
|
|
|
+ // closeLoading();
|
|
|
this.isAbove = false;
|
|
|
console.log("onEnter");
|
|
|
+ console.log(this.props.path, "onEnter");
|
|
|
},
|
|
|
onEnterBack: () => {
|
|
|
- openLoading();
|
|
|
- console.log("onEnterBack");
|
|
|
+ // openLoading();
|
|
|
+ console.log(this.props.path, "onEnterBack");
|
|
|
this.isBelow = false;
|
|
|
},
|
|
|
onLeave: () => {
|
|
|
- console.log("onLeave");
|
|
|
+ console.log(this.props.path, "onLeave");
|
|
|
this.isAbove = true;
|
|
|
- openLoading();
|
|
|
+ // openLoading();
|
|
|
},
|
|
|
onLeaveBack: () => {
|
|
|
- console.log("onLeaveBack");
|
|
|
- openLoading();
|
|
|
+ console.log(this.props.path, "onLeaveBack");
|
|
|
+ // openLoading();
|
|
|
this.isBelow = true;
|
|
|
},
|
|
|
},
|
|
@@ -207,30 +219,53 @@ export default class Viewer extends Component {
|
|
|
|
|
|
initializeEnterTween() {
|
|
|
const duration = this.props.enterTween.duration || 1;
|
|
|
- console.log("initializeEnterTween", duration, this.props.enterTween.pin);
|
|
|
+ let openPin = false;
|
|
|
+ console.warn("this.props.enterTween", this.props.enterTween);
|
|
|
gsap.set(this.viewerRef.current, {
|
|
|
yPercent: -100 * duration,
|
|
|
});
|
|
|
- if (this.props.enterTween.pin !== 0) {
|
|
|
- console.warn("tutu", this.props.enterTween.pin);
|
|
|
- this.enterTimeline = gsap.timeline({
|
|
|
- scrollTrigger: {
|
|
|
- trigger: this.viewerRef.current,
|
|
|
- scrub: true,
|
|
|
- pin: this.props.enterTween.pin,
|
|
|
- start: function () {
|
|
|
- return "top top";
|
|
|
+ if (void 0 !== this.props.enterTween.pin) {
|
|
|
+ openPin = this.props.enterTween.pin;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.enterTimeline = gsap.timeline({
|
|
|
+ scrollTrigger: {
|
|
|
+ trigger: this.viewerRef.current,
|
|
|
+ scrub: true,
|
|
|
+ pin: openPin,
|
|
|
+ start: function () {
|
|
|
+ return "top top";
|
|
|
+ },
|
|
|
+ end: function () {
|
|
|
+ return "top top-=" + window.innerHeight * duration;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ });
|
|
|
+ if (this.props.enterTween.to) {
|
|
|
+ this.enterTimeline.to(
|
|
|
+ this.viewerRef.current,
|
|
|
+ Object.assign(
|
|
|
+ {
|
|
|
+ ease: "none",
|
|
|
},
|
|
|
- end: function () {
|
|
|
- return "top top-=" + window.innerHeight * duration;
|
|
|
+ this.props.enterTween.to
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (this.props.enterTween.from) {
|
|
|
+ this.enterTimeline.from(
|
|
|
+ this.viewerRef.current,
|
|
|
+ Object.assign(
|
|
|
+ {
|
|
|
+ ease: "none",
|
|
|
},
|
|
|
- },
|
|
|
- });
|
|
|
+ this.props.enterTween.from
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
initializeExitTween() {
|
|
|
console.log(this.props.path, "initializing exit tween ");
|
|
|
- console.warn("this.props.exitTween", this.props.exitTween);
|
|
|
this.exitTimeline = gsap.timeline({
|
|
|
scrollTrigger: {
|
|
|
scrub: true,
|
|
@@ -247,6 +282,18 @@ export default class Viewer extends Component {
|
|
|
},
|
|
|
},
|
|
|
});
|
|
|
+
|
|
|
+ if (this.props.exitTween.from) {
|
|
|
+ this.exitTimeline.from(
|
|
|
+ this.viewerRef.current,
|
|
|
+ Object.assign(
|
|
|
+ {
|
|
|
+ ease: "none",
|
|
|
+ },
|
|
|
+ this.props.exitTween.from
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
poolNewFrames(index) {
|
|
@@ -305,59 +352,57 @@ export default class Viewer extends Component {
|
|
|
return (
|
|
|
<>
|
|
|
<div
|
|
|
+ className="processBar"
|
|
|
css={css`
|
|
|
- position: "relative";
|
|
|
- margin: "auto";
|
|
|
- textalign: "center";
|
|
|
- pointerevents: "none";
|
|
|
- maxwidth: "100vw";
|
|
|
+ position: fixed;
|
|
|
+ top: calc(100vh - 4px);
|
|
|
+ // top: calc(var(--vh, 1vh) * 100 - 4px);
|
|
|
+ left: 0;
|
|
|
+ width: 100vw;
|
|
|
+ max-width: 100%;
|
|
|
+ border-top: 1px solid rgba(33, 33, 44, 0.6);
|
|
|
+ background-color: rgba(17, 17, 34, 0.6);
|
|
|
+ height: 4px;
|
|
|
+ z-index: 9;
|
|
|
`}
|
|
|
- ref={this.containerRef}
|
|
|
- style={{ height: this.props.height || "500vh" }}
|
|
|
>
|
|
|
- <div>{this.props.name}</div>
|
|
|
- <div className="loading-wrap" ref={this.loadingWrap}></div>
|
|
|
-
|
|
|
<div
|
|
|
css={css`
|
|
|
- position: fixed;
|
|
|
- top: calc(100vh - 4px);
|
|
|
- // top: calc(var(--vh, 1vh) * 100 - 4px);
|
|
|
+ position: absolute;
|
|
|
+ width: auto;
|
|
|
+ height: 4px;
|
|
|
left: 0;
|
|
|
- width: 100vw;
|
|
|
- max-width: 100%;
|
|
|
- border-top: 1px solid rgba(33, 33, 44, 0.6);
|
|
|
- background-color: rgba(17, 17, 34, 0.6);
|
|
|
+ bottom: 0;
|
|
|
+ z-index: 10;
|
|
|
+ background-color: rgba(120, 120, 163, 0.33);
|
|
|
+ `}
|
|
|
+ ref={this.preProcessingRef}
|
|
|
+ ></div>
|
|
|
+ <div
|
|
|
+ css={css`
|
|
|
+ position: absolute;
|
|
|
+ width: auto;
|
|
|
height: 4px;
|
|
|
- z-index: 9;
|
|
|
+ left: 0;
|
|
|
+ bottom: 0;
|
|
|
+ z-index: 10;
|
|
|
+ background-color: hsla(0, 0%, 79.2%, 0.5);
|
|
|
`}
|
|
|
- >
|
|
|
- <div
|
|
|
- css={css`
|
|
|
- position: absolute;
|
|
|
- width: auto;
|
|
|
- height: 4px;
|
|
|
- left: 0;
|
|
|
- bottom: 0;
|
|
|
- z-index: 10;
|
|
|
- background-color: rgba(120, 120, 163, 0.33);
|
|
|
- `}
|
|
|
- ref={this.preProcessingRef}
|
|
|
- ></div>
|
|
|
- <div
|
|
|
- css={css`
|
|
|
- position: absolute;
|
|
|
- width: auto;
|
|
|
- height: 4px;
|
|
|
- left: 0;
|
|
|
- bottom: 0;
|
|
|
- z-index: 10;
|
|
|
- background-color: hsla(0, 0%, 79.2%, 0.5);
|
|
|
- `}
|
|
|
- ref={this.processingRef}
|
|
|
- ></div>
|
|
|
- </div>
|
|
|
+ ref={this.processingRef}
|
|
|
+ ></div>
|
|
|
+ </div>
|
|
|
|
|
|
+ <div
|
|
|
+ css={css`
|
|
|
+ position: relative;
|
|
|
+ margin: auto;
|
|
|
+ text-align: center;
|
|
|
+ pointer-events: none;
|
|
|
+ max-width: 100vw;
|
|
|
+ `}
|
|
|
+ ref={this.containerRef}
|
|
|
+ style={{ height: this.props.height || "500vh" }}
|
|
|
+ >
|
|
|
<div ref={this.viewerRef}>
|
|
|
<div style={{ overflow: "hidden" }}>
|
|
|
<canvas
|
|
@@ -365,6 +410,7 @@ export default class Viewer extends Component {
|
|
|
width: auto;
|
|
|
margin-left: 50%;
|
|
|
transform: translateX(-50%);
|
|
|
+ height: 100vh;
|
|
|
height: calc(var(--vh, 1vh) * 100);
|
|
|
`}
|
|
|
ref={this.canvasRef}
|