ant-design/site/theme/template/Home/Banner/Background.tsx
二货机器人 abf215a982
docs: Update 4.0 site (#20290)
* init recommend block

* init design pages

* home frames

* add background banner

* hello, Hitu makes the animation

* add media query

* add images

* update types

* add declare

* preload support

* update ignore

* additional ignore site Home lint

* update ignore

* add hover effect

* adjust alt of bannber

* adjust lang & card shadow

* fix typo

* adjust desc

* hitu in english

* article add link

* Certainty is hitu

* Meaning Hitu

* Growth with Hitu

* Natural Hitu

* slow down of Natural

* adjust speed of icons

* New Meaning animation

* adjust animation duration

* update card link

* update link

* values doc

* replace images

* faster Growth

* update values

* fix lint

* all slow down

* adjust padding

* update icons

* adjust margin

* update images

* adjust montion

* adjust by designer

* update pages

* update design prod

* update articles

* update site style

* update doc

* update images

* update style

* lint fix

* adjust liner color

* github text color update

* adjust margin of title

* mobile design

* update design sub card

* update style

* less lint

* update images

* design card auto height

* update img

* update logo transition

* adjust card style

* adjust style to fix 184

* adjust nav style

* category it

* slow down of logo

* update style

* hide video link

* hitu article

* use img of hitu

* update docs

* style lint

* update Hitu layout doc

* update images

* speed up logo

* update link

* clean up

* clean up

* update doc

* adjust doc

* update images
2019-12-26 15:27:52 +08:00

187 lines
5.5 KiB
TypeScript

import * as React from 'react';
import Hitu from '@ant-design/hitu';
import './Background.less';
const RANDOM_OFFSET = 20;
const TOTAL_FRAMES = 500;
function randomFrames(x: number, y: number): any[] {
const common = { x, y, cubic: Hitu.CUBIC_EASE_IN_OUT };
return [
{
frame: 0,
...common,
},
{
frame: TOTAL_FRAMES / 2,
...common,
x: x - Math.random() * RANDOM_OFFSET * 2 + RANDOM_OFFSET,
y: y - Math.random() * RANDOM_OFFSET * 2 + RANDOM_OFFSET,
},
{
frame: TOTAL_FRAMES,
...common,
},
];
}
const ShadowSize = 30;
// =================================== Circle 1 ===================================
const CircleSize1 = 140;
const Circle1 = () => (
<svg>
<defs>
<filter id="banner-circle-shadow-1">
<feDropShadow dx="10" dy="10" stdDeviation="10" floodColor="rgba(0,0,0,0.05)" />
</filter>
<linearGradient id="banner-circle-fill-1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style={{ stopColor: '#FAFCFE' }} />
<stop offset="100%" style={{ stopColor: '#F9FCFE' }} />
</linearGradient>
</defs>
<circle
cx={CircleSize1 + ShadowSize}
cy={CircleSize1 + ShadowSize}
r={CircleSize1}
fill="url(#banner-circle-fill-1)"
filter="url(#banner-circle-shadow-1)"
/>
</svg>
);
Circle1.width = (CircleSize1 + ShadowSize) * 2;
Circle1.height = (CircleSize1 + ShadowSize) * 2;
// =================================== Circle 2 ===================================
const CircleSize2 = 200;
const Circle2 = () => (
<svg>
<defs>
<filter id="banner-circle-shadow-2">
<feDropShadow dx="10" dy="10" stdDeviation="10" floodColor="rgba(0,0,0,0.05)" />
</filter>
<linearGradient id="banner-circle-fill-2" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style={{ stopColor: '#FAFCFE' }} />
<stop offset="100%" style={{ stopColor: '#F9FCFE' }} />
</linearGradient>
</defs>
<circle
cx={CircleSize2 + ShadowSize}
cy={CircleSize2 + ShadowSize}
r={CircleSize2}
fill="url(#banner-circle-fill-2)"
filter="url(#banner-circle-shadow-2)"
/>
</svg>
);
Circle2.width = (CircleSize2 + ShadowSize) * 2;
Circle2.height = (CircleSize2 + ShadowSize) * 2;
// ==================================== Rect 1 ====================================
const ReactSize1 = 90;
const React1 = () => (
<svg>
<defs>
<filter id="banner-rect-shadow-1">
<feDropShadow dx="10" dy="10" stdDeviation="10" floodColor="rgba(0,0,0,0.05)" />
</filter>
<linearGradient id="banner-rect-fill-1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style={{ stopColor: '#F8FBFF' }} />
<stop offset="100%" style={{ stopColor: '#F9FCFF' }} />
</linearGradient>
</defs>
<rect
x={ShadowSize}
y={ShadowSize}
width={ReactSize1 * 2}
height={ReactSize1 * 2}
fill="url(#banner-rect-fill-1)"
filter="url(#banner-rect-shadow-1)"
/>
</svg>
);
React1.width = (ReactSize1 + ShadowSize) * 2;
React1.height = (ReactSize1 + ShadowSize) * 2;
// ================================== Diamond 1 ===================================
const DiamondSize1 = 180;
const Diamond1 = () => {
const start = ShadowSize;
const center = ShadowSize + DiamondSize1;
const end = ShadowSize + DiamondSize1 * 2;
return (
<svg>
<defs>
<filter id="banner-diamond-shadow-1">
<feDropShadow dx="10" dy="10" stdDeviation="10" floodColor="rgba(0,0,0,0.05)" />
</filter>
<linearGradient id="banner-diamond-fill-1" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" style={{ stopColor: '#F8FBFF' }} />
<stop offset="100%" style={{ stopColor: '#F9FCFF' }} />
</linearGradient>
</defs>
<path
d={`M ${start} ${center} ${center} ${start} ${end} ${center} ${center} ${end} Z`}
fill="url(#banner-diamond-fill-1)"
filter="url(#banner-diamond-shadow-1)"
/>
</svg>
);
};
Diamond1.width = (DiamondSize1 + ShadowSize) * 2;
Diamond1.height = (DiamondSize1 + ShadowSize) * 2;
export default function Background() {
const [circleFrames, setCircleFrames] = React.useState<any[]>(randomFrames(550, 200));
const [circle2Frames, setCircle2Frames] = React.useState<any[]>(randomFrames(0, 448));
const [reactFrames, setReactFrames] = React.useState<any[]>(randomFrames(1400, 300));
const [diamondFrames, setDiamondFrames] = React.useState<any[]>(randomFrames(1100, 0));
return (
<div className="home-banner-background">
<img
alt="background"
src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*_fCZRqKuJBgAAAAAAAAAAABkARQnAQ"
/>
<Hitu
width={1440}
height={448}
frames={TOTAL_FRAMES}
onFrame={frame => {
if (frame === 0) {
setCircleFrames(randomFrames(550, 200));
setCircle2Frames(randomFrames(0, 448));
setReactFrames(randomFrames(1400, 300));
setDiamondFrames(randomFrames(1100, 0));
}
}}
shapes={[
{
type: 'shape',
source: Circle1,
frames: circleFrames,
},
{
type: 'shape',
source: Circle2,
frames: circle2Frames,
},
{
type: 'shape',
source: React1,
frames: reactFrames,
},
{
type: 'shape',
source: Diamond1,
frames: diamondFrames,
},
]}
/>
</div>
);
}