feat: 滚动
This commit is contained in:
parent
fcc2086f12
commit
5b3f929c39
|
@ -7,10 +7,15 @@ export interface IOnScrollParam {
|
||||||
height: number;
|
height: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IModel {
|
||||||
|
top: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
className: string;
|
className: string;
|
||||||
data: any;
|
data: any;
|
||||||
onScroll?: (p: IOnScrollParam) => void;
|
onScroll?: (p: IOnScrollParam) => void;
|
||||||
|
model?: IModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,6 +67,10 @@ function TimeScroll(props: IProps) {
|
||||||
setCursorActive((p) => ({ ...p, top: mouseY - orbitClient.top - 4 }));
|
setCursorActive((p) => ({ ...p, top: mouseY - orbitClient.top - 4 }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCursorStatic((p) => ({ ...p, top: props.model!.top }));
|
||||||
|
}, [props.model]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.onScroll)
|
if (props.onScroll)
|
||||||
props.onScroll({
|
props.onScroll({
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
.recommends {
|
.recommends {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 2fr 1fr 1fr;
|
grid-template-columns: 1fr 1.5fr 1fr;
|
||||||
grid-column-gap: 20px;
|
grid-column-gap: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@ import { Icon } from "@ricons/utils";
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const scrollContainerRef = useRef<HTMLElement | null>(null);
|
const scrollContainerRef = useRef<HTMLElement | null>(null);
|
||||||
|
const ratioRef = useRef<number>(1);
|
||||||
|
const [timescroll, setTimescroll] = useState({
|
||||||
|
top: -4,
|
||||||
|
});
|
||||||
|
|
||||||
const dropList = (
|
const dropList = (
|
||||||
<Menu>
|
<Menu>
|
||||||
|
@ -56,8 +60,16 @@ export default function Index() {
|
||||||
const { top, height } = p;
|
const { top, height } = p;
|
||||||
//左侧区域高度
|
//左侧区域高度
|
||||||
const { scrollHeight, clientHeight } = scrollContainerRef.current!;
|
const { scrollHeight, clientHeight } = scrollContainerRef.current!;
|
||||||
const ratio = (scrollHeight - clientHeight) / height;
|
ratioRef.current = (scrollHeight - clientHeight) / height;
|
||||||
scrollContainerRef.current!.scrollTop = top * ratio;
|
scrollContainerRef.current!.scrollTop = top * ratioRef.current;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onScroll = () => {
|
||||||
|
const { scrollHeight, scrollTop } = scrollContainerRef.current!;
|
||||||
|
const isTop = scrollTop === 0;
|
||||||
|
const isBottom = scrollTop === scrollHeight;
|
||||||
|
const top = scrollTop / ratioRef.current;
|
||||||
|
setTimescroll({ top: isTop ? -4 : top });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -100,7 +112,7 @@ export default function Index() {
|
||||||
</div>
|
</div>
|
||||||
<div className="timeline">
|
<div className="timeline">
|
||||||
<div className="thumbnail">
|
<div className="thumbnail">
|
||||||
<article ref={scrollContainerRef}>
|
<article ref={scrollContainerRef} onScroll={onScroll}>
|
||||||
{courseTimeList.map((item, index) => (
|
{courseTimeList.map((item, index) => (
|
||||||
<section key={index}>
|
<section key={index}>
|
||||||
<div className="time">
|
<div className="time">
|
||||||
|
@ -120,6 +132,7 @@ export default function Index() {
|
||||||
className="timescroll"
|
className="timescroll"
|
||||||
data={courseTimeList}
|
data={courseTimeList}
|
||||||
onScroll={onTimeScroll}
|
onScroll={onTimeScroll}
|
||||||
|
model={{ top: timescroll.top }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user