看到了react-three-fiber作者展示的作品https://codesandbox.io/embed/r3f-moksha-f1ixt,心声敬佩,大呼卧草,就想能不能用这个套子做一个数据展示的东
西,于是搞起。
先看一下效果,虽然写的跟大佬的比就是shi,但是还是记录一下知识点:
- 图表部分使用的是plotly
1. 滚动实现
- 通过滚动栏控制position的y
- 通过offset和factor来控制各个block的位置,以及位置变更方向
function Block({
children, offset, factor, ...props }) {
const {
offset: parentOffset, sectionHeight } = useBlock();
const ref = useRef();
offset = offset !== undefined ? offset : parentOffset;
useFrame(() => {
const curY = ref.current.position.y;
const curTop = state.top.current;
ref.current.position.y = lerp(curY, (curTop / state.zoom) * factor, 0.1)
});
return (
<offsetContext.Provider value=