【发布时间】:2020-09-07 14:18:45
【问题描述】:
我在 react 中做了一些动画代码,但是我收到了这个错误,getKeyFrames 和 getTiming 没有定义,我的代码中有一些问题,它没有得到我的功能
./src/WithLigin.js
Line 59:5: 'getKeyFrames' is not defined no-undef
Line 68:5: 'getTiming' is not defined no-undef
Search for the keywords to learn more about each error.
在这里我附上了我的整个代码,任何人都可以查看它并帮助我解决这个问题吗?任何帮助将不胜感激。
import React,{ useRef, useState } from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Redirect,
withRouter,
NavLink
} from "react-router-dom";
import ScrollToTop from "./scrollToTop";
import App from "./App";
import { useAuth0 } from "@auth0/auth0-react";
import { useSpring, animated, useTransition } from 'react-spring';
//import { useGesture } from 'react-use-gesture';
import { AnimationSequence, Animatable } from 'react-web-animation';
const LoginButton = () => {
const { loginWithRedirect, isAuthenticated, isLoading, error } = useAuth0();
const scrollingLeft = useSpring({
from: { transform: "translate(60%,0)" },
to: { transform: "translate(20%,0)" },
config: { duration: 1000 },
reset: true
});
const scrollingRight = useSpring({
from: { transform: "translate(-60%,0)" },
to: { transform: "translate(20%,0)" },
config: { duration: 1000 },
reset: true
});
const [items, set] = useState([1, 2, 3, 4]);
const [currentTime,setCurrentTime] = useState('0');
const [playState,setPlayState] = useState('running');
const transitions = useTransition(items, item => item.key, {
from: { transform: 'translate3d(0,-40px,0)' },
enter: { transform: 'translate3d(0,0px,0)' },
leave: { transform: 'translate3d(0,-40px,0)' },
})
getKeyFrames=() => {
return [
{ transform: 'scale(1)', opacity: 1, offset: 0 },
{ transform: 'scale(.5)', opacity: 0.5, offset: 0.3 },
{ transform: 'scale(.667)', opacity: 0.667, offset: 0.7875 },
{ transform: 'scale(.6)', opacity: 0.6, offset: 1 },
];
};
getTiming=(duration) => {
return {
duration,
easing: 'ease-in-out',
delay: 0,
iterations: 2,
direction: 'alternate',
fill: 'forwards',
};
}
return (
<Router>
<div className="full_width">
<AnimationSequence
playState={playState}
currentTime={currentTime}
>
<Animatable.div
id="1"
keyframes={this.getKeyFrames()}
timing={this.getTiming(2000)}
>
Web Animations API Rocks
</Animatable.div>
<Animatable.div
id="2"
keyframes={this.getKeyFrames()}
timing={this.getTiming(4000)}
>
It really does!
</Animatable.div>
</AnimationSequence>
</div>
</Router>
);
};
export default LoginButton;
【问题讨论】:
-
您正在使用功能组件,
this无效。直接拨打getKeyFrames()。
标签: reactjs