|
@@ -1,31 +1,103 @@
|
|
|
import { Component, createRef } from "react";
|
|
|
import gsap from "gsap";
|
|
|
import PropTypes from "prop-types";
|
|
|
+import { Action } from "../action";
|
|
|
import { css } from "@emotion/react";
|
|
|
|
|
|
-export default class TimeLineText extends Component {
|
|
|
- constructor(props) {
|
|
|
+export function TimeLinePureText(props) {
|
|
|
+ const progressPosition = props.progressPosition
|
|
|
+ ? props.progressPosition
|
|
|
+ : 0.5;
|
|
|
+ const fade = props.fade || 0.04;
|
|
|
+ const duration = props.duration || 0.1;
|
|
|
+ const verticalOffset = props.verticalOffset || "50vh";
|
|
|
+ const keyframes = [
|
|
|
+ Object.assign({}, Action.fadeUp, {
|
|
|
+ start: progressPosition,
|
|
|
+ end: progressPosition + fade,
|
|
|
+ }),
|
|
|
+ Object.assign({}, Action.fadeDown, {
|
|
|
+ start: progressPosition + duration + fade,
|
|
|
+ end: progressPosition + duration + fade + fade,
|
|
|
+ }),
|
|
|
+ ];
|
|
|
+
|
|
|
+ console.log("keyframes", keyframes);
|
|
|
+ return (
|
|
|
+ <TimeLineText
|
|
|
+ trigger={Action.scrubPin}
|
|
|
+ keyframes={keyframes}
|
|
|
+ verticalOffset={verticalOffset}
|
|
|
+ className={props.className}
|
|
|
+ parentHeight={props.parentHeight}
|
|
|
+ progressPosition={props.progressPosition}
|
|
|
+ style={props.style}
|
|
|
+ >
|
|
|
+ {props.children}
|
|
|
+ </TimeLineText>
|
|
|
+ );
|
|
|
+}
|
|
|
+export function TimeLineWallText(props) {
|
|
|
+ const progressPosition =
|
|
|
+ void 0 !== props.progressPosition ? props.progressPosition : 0.5;
|
|
|
+ const fade = props.fade || 0.025;
|
|
|
+ const duration = props.duration || 0.05;
|
|
|
+ const verticalOffset = props.verticalOffset || "46.5vh";
|
|
|
+
|
|
|
+ const keyframes = [
|
|
|
+ Object.assign({}, Action.fadeIn, {
|
|
|
+ start: progressPosition,
|
|
|
+ end: progressPosition + fade,
|
|
|
+ }),
|
|
|
+ Object.assign({}, Action.fadeOut, {
|
|
|
+ start: progressPosition + duration + fade,
|
|
|
+ end: progressPosition + duration + fade + fade,
|
|
|
+ }),
|
|
|
+ ];
|
|
|
+
|
|
|
+ return (
|
|
|
+ <TimeLineText
|
|
|
+ trigger={Action.scrubPin}
|
|
|
+ keyframes={keyframes}
|
|
|
+ verticalOffset={verticalOffset}
|
|
|
+ className={props.className}
|
|
|
+ parentHeight={props.parentHeight}
|
|
|
+ style={props.style}
|
|
|
+ progressPosition={props.progressPosition}
|
|
|
+ {...props}
|
|
|
+ >
|
|
|
+ {props.children}
|
|
|
+ </TimeLineText>
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+export class TimeLineText extends Component {
|
|
|
+ constructor() {
|
|
|
super();
|
|
|
this.containerRef = createRef();
|
|
|
this.timeline = false;
|
|
|
this.top = 0;
|
|
|
- this.init(props);
|
|
|
+ this.keyframes = [];
|
|
|
+ this.trigger = false;
|
|
|
}
|
|
|
init(props) {
|
|
|
console.log("props", props);
|
|
|
}
|
|
|
componentWillUnmount() {
|
|
|
- console.error("remove-timeline");
|
|
|
if (this.timeline) {
|
|
|
+ console.error("remove-timeline");
|
|
|
this.timeline.kill(true);
|
|
|
this.timeline = false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
componentDidMount() {
|
|
|
if (this.props.keyframes && this.props.trigger) {
|
|
|
- // var n = this.props.keyframes[0].start;
|
|
|
- // this.setTop(n);
|
|
|
+ var n = this.props.keyframes[0].start || 0;
|
|
|
+ this.setTop(n);
|
|
|
this.createTimeLine();
|
|
|
+ } else {
|
|
|
+ this.props.progressPosition && this.setTop(this.props.progressPosition);
|
|
|
}
|
|
|
}
|
|
|
setTop(height) {
|
|
@@ -34,7 +106,6 @@ export default class TimeLineText extends Component {
|
|
|
((height * window.innerHeight * ((parentHeight - 100) / 100)) /
|
|
|
((window.innerHeight * parentHeight) / 100)) *
|
|
|
100;
|
|
|
- // debugger;
|
|
|
this.top = lastHeight + "%";
|
|
|
console.log("this.top", this.top);
|
|
|
}
|
|
@@ -51,10 +122,12 @@ export default class TimeLineText extends Component {
|
|
|
const timeRes =
|
|
|
(lastE - start) * (parseFloat(this.props.parentHeight) - 100);
|
|
|
console.log("timeRes", timeRes);
|
|
|
+ debugger;
|
|
|
|
|
|
this.timeline = gsap.timeline({
|
|
|
- scrollTrigger: {
|
|
|
- ...{
|
|
|
+ scrollTrigger: Object.assign(
|
|
|
+ {},
|
|
|
+ {
|
|
|
trigger: this.containerRef.current,
|
|
|
start: "top top",
|
|
|
end: "+=" + timeRes + "%",
|
|
@@ -62,8 +135,8 @@ export default class TimeLineText extends Component {
|
|
|
console.warn("onEnter");
|
|
|
},
|
|
|
},
|
|
|
- ...this.props.trigger,
|
|
|
- },
|
|
|
+ this.props.trigger
|
|
|
+ ),
|
|
|
});
|
|
|
for (var i = 0; i < this.props.keyframes.length; i += 1) {
|
|
|
const cFrame = this.props.keyframes[i];
|
|
@@ -94,6 +167,19 @@ export default class TimeLineText extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ createNormalTextTimeLine() {
|
|
|
+ console.log("createNormalTextTimeLine");
|
|
|
+ if (!this.timeline) {
|
|
|
+ this.timeline = gsap.timeline({
|
|
|
+ scrollTrigger: {
|
|
|
+ pin: true,
|
|
|
+ scrub: true,
|
|
|
+ trigger: this.containerRef.current,
|
|
|
+ start: "top top",
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
render() {
|
|
|
const top =
|
|
|
"calc(var(--vh, 1vh) *" + parseFloat(this.props.verticalOffset) + ")";
|
|
@@ -145,12 +231,21 @@ export default class TimeLineText extends Component {
|
|
|
|
|
|
TimeLineText.propTypes = {
|
|
|
verticalOffset: PropTypes.string,
|
|
|
- children: PropTypes.object,
|
|
|
+ children: PropTypes.any,
|
|
|
trigger: PropTypes.object,
|
|
|
parentHeight: PropTypes.string,
|
|
|
keyframes: PropTypes.arrayOf(PropTypes.object),
|
|
|
+ progressPosition: PropTypes.number,
|
|
|
};
|
|
|
|
|
|
TimeLineText.defaultProps = {
|
|
|
verticalOffset: "100vh",
|
|
|
};
|
|
|
+
|
|
|
+TimeLinePureText.propTypes = {
|
|
|
+ ...TimeLineText.propTypes,
|
|
|
+};
|
|
|
+
|
|
|
+TimeLineWallText.propTypes = {
|
|
|
+ ...TimeLineText.propTypes,
|
|
|
+};
|