Navigation Menu

Skip to content

Commit

Permalink
end video 3
Browse files Browse the repository at this point in the history
  • Loading branch information
codereviewvideos committed Oct 27, 2018
1 parent 179ac67 commit e401372
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/AnimatedBackground.tsx
Expand Up @@ -12,6 +12,8 @@ interface IAnimatedBackgroundState {


class AnimatedBackground extends React.Component<any, IAnimatedBackgroundState> { class AnimatedBackground extends React.Component<any, IAnimatedBackgroundState> {


private interval: any;

public constructor(props: any) { public constructor(props: any) {
super(props); super(props);


Expand All @@ -30,13 +32,23 @@ class AnimatedBackground extends React.Component<any, IAnimatedBackgroundState>
}; };
} }


public componentDidMount(): void {
this.interval = setInterval(() => this.updateGradient(), 10);
}

public componentWillUnmount(): void {
clearInterval(this.interval);
}

public render() { public render() {
this.determineNextColourCombo(); const [colour1, colour2] = this.determineNextColourCombo();


setInterval(this.updateGradient.bind(this), 1000); const css = {
background: "-webkit-gradient(linear, left top, right top, from("+colour1+"), to("+colour2+"))"
};


return ( return (
<div className="AnimatedBackground "> <div className="AnimatedBackground" style={css}>
hello hello
</div> </div>
); );
Expand Down Expand Up @@ -68,21 +80,13 @@ class AnimatedBackground extends React.Component<any, IAnimatedBackgroundState>
} }


private updateGradient() { private updateGradient() {
// $('#gradient').css({
// background: "-webkit-gradient(linear, left top, right top, from("+colour1+"), to("+colour2+"))"}).css({
// background: "-moz-linear-gradient(left, "+colour1+" 0%, "+colour2+" 100%)"});

const {colours, colourIndices, gradientSpeed, step} = this.state; const {colours, colourIndices, gradientSpeed, step} = this.state;


this.setState({ this.setState({
step: step + gradientSpeed step: step + gradientSpeed
}); });


if (step >= 1) { if (step >= 1) {
this.setState({
step: step % 1
});

colourIndices[0] = colourIndices[1]; colourIndices[0] = colourIndices[1];
colourIndices[2] = colourIndices[3]; colourIndices[2] = colourIndices[3];


Expand All @@ -91,6 +95,9 @@ class AnimatedBackground extends React.Component<any, IAnimatedBackgroundState>
colourIndices[1] = (colourIndices[1] + Math.floor(1 + Math.random() * (colours.length - 1))) % colours.length; colourIndices[1] = (colourIndices[1] + Math.floor(1 + Math.random() * (colours.length - 1))) % colours.length;
colourIndices[3] = (colourIndices[3] + Math.floor(1 + Math.random() * (colours.length - 1))) % colours.length; colourIndices[3] = (colourIndices[3] + Math.floor(1 + Math.random() * (colours.length - 1))) % colours.length;


this.setState({
step: step % 1
});
} }
} }
} }
Expand Down

0 comments on commit e401372

Please sign in to comment.