|
|
@@ -1,11 +1,23 @@ |
|
|
|
|
|
import miniHeaderImage from '@/assets/img/home/header-bg-mini.png'; |
|
|
|
|
|
import headerImage from '@/assets/img/home/header-bg.png'; |
|
|
import { convertRemToPx } from '@/utils'; |
|
|
import { convertRemToPx } from '@/utils'; |
|
|
import { useNavigate } from '@umijs/max'; |
|
|
import { useNavigate } from '@umijs/max'; |
|
|
import { motion, useMotionTemplate, useScroll, useSpring, useTransform } from 'motion/react'; |
|
|
|
|
|
|
|
|
import { |
|
|
|
|
|
motion, |
|
|
|
|
|
useMotionTemplate, |
|
|
|
|
|
useMotionValueEvent, |
|
|
|
|
|
useScroll, |
|
|
|
|
|
useSpring, |
|
|
|
|
|
useTransform, |
|
|
|
|
|
} from 'motion/react'; |
|
|
|
|
|
import { useState } from 'react'; |
|
|
import NavBar from '../NavBar'; |
|
|
import NavBar from '../NavBar'; |
|
|
import StatisticsBlock from '../Statistics'; |
|
|
import StatisticsBlock from '../Statistics'; |
|
|
import styles from './index.less'; |
|
|
import styles from './index.less'; |
|
|
|
|
|
|
|
|
function IntroBlock() { |
|
|
function IntroBlock() { |
|
|
|
|
|
const [backgroundImage1, setBackgroundImage1] = useState(undefined); |
|
|
|
|
|
const [backgroundImage2, setBackgroundImage2] = useState(headerImage); |
|
|
const navigate = useNavigate(); |
|
|
const navigate = useNavigate(); |
|
|
const { scrollY } = useScroll(); |
|
|
const { scrollY } = useScroll(); |
|
|
const springValue = useSpring(scrollY, { |
|
|
const springValue = useSpring(scrollY, { |
|
|
@@ -15,10 +27,8 @@ function IntroBlock() { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const initialHeight = convertRemToPx(35); |
|
|
const initialHeight = convertRemToPx(35); |
|
|
console.log(initialHeight); |
|
|
|
|
|
|
|
|
|
|
|
const height = useTransform(() => `max(calc(35rem - ${springValue.get()}px), 5rem)`); |
|
|
|
|
|
// const left = useTransform(() => `min(${springValue.get()}px, 16.25rem)`); |
|
|
|
|
|
|
|
|
const minHeight = convertRemToPx(4.7); |
|
|
|
|
|
const height = useTransform(() => `max(calc(35rem - ${springValue.get()}px), 4.7rem)`); |
|
|
const left = useTransform(springValue, [0, initialHeight], [0.0, 16.25]); |
|
|
const left = useTransform(springValue, [0, initialHeight], [0.0, 16.25]); |
|
|
const leftRem = useMotionTemplate`${left}rem`; |
|
|
const leftRem = useMotionTemplate`${left}rem`; |
|
|
const radius = useTransform(springValue, [0, initialHeight], [0.0, 2.5]); |
|
|
const radius = useTransform(springValue, [0, initialHeight], [0.0, 2.5]); |
|
|
@@ -26,6 +36,10 @@ function IntroBlock() { |
|
|
const top = useTransform(springValue, [0, initialHeight], [0, 10]); |
|
|
const top = useTransform(springValue, [0, initialHeight], [0, 10]); |
|
|
const paddingX = useTransform(springValue, [0, initialHeight], [16.25, 10]); |
|
|
const paddingX = useTransform(springValue, [0, initialHeight], [16.25, 10]); |
|
|
const paddingXRem = useMotionTemplate`1.25rem ${paddingX}rem 0`; |
|
|
const paddingXRem = useMotionTemplate`1.25rem ${paddingX}rem 0`; |
|
|
|
|
|
useMotionValueEvent(scrollY, 'change', (value) => { |
|
|
|
|
|
setBackgroundImage1(value > initialHeight - minHeight ? miniHeaderImage : undefined); |
|
|
|
|
|
setBackgroundImage2(value > initialHeight - minHeight ? undefined : headerImage); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<motion.div |
|
|
<motion.div |
|
|
@@ -36,13 +50,17 @@ function IntroBlock() { |
|
|
right: leftRem, |
|
|
right: leftRem, |
|
|
borderRadius: radiusRem, |
|
|
borderRadius: radiusRem, |
|
|
top: top, |
|
|
top: top, |
|
|
|
|
|
backgroundImage: `url(${backgroundImage1})`, |
|
|
}} |
|
|
}} |
|
|
transition={{ |
|
|
transition={{ |
|
|
type: 'spring', |
|
|
type: 'spring', |
|
|
duration: 0.3, |
|
|
duration: 0.3, |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
<motion.div className={styles['intro__content']} style={{ padding: paddingXRem }}> |
|
|
|
|
|
|
|
|
<motion.div |
|
|
|
|
|
className={styles['intro__content']} |
|
|
|
|
|
style={{ padding: paddingXRem, backgroundImage: `url(${backgroundImage2})` }} |
|
|
|
|
|
> |
|
|
<NavBar></NavBar> |
|
|
<NavBar></NavBar> |
|
|
<div className={styles['intro__title']}>智能材料科研平台</div> |
|
|
<div className={styles['intro__title']}>智能材料科研平台</div> |
|
|
<div className={styles['intro__desc']}> |
|
|
<div className={styles['intro__desc']}> |
|
|
|