【问题标题】:Making fixed sidebar starts scrolling when it reach to the footer制作固定侧边栏在到达页脚时开始滚动
【发布时间】:2021-05-19 15:02:06
【问题描述】:

我必须制作一个固定的侧边栏,当它到达 React.js 中的页脚时它开始向上滚动, 我想在不使用 jquery 的情况下使用纯 javascript 和 CSS。请通过一些代码给我一些建议或帮助。

【问题讨论】:

    标签: javascript html jquery css reactjs


    【解决方案1】:

    我总是在我的项目中使用“react-sticky-box”。它是为与纯 js 做出反应而构建的。下面你可以看到一个你想要的例子。 (另请阅读documentation

    安装:

    npm install react-sticky-box
    

    例子:

    import React from "react";
    import StickyBox from "react-sticky-box";
    const Page = () => (
      <div className="row">
        <StickyBox offsetTop={20} offsetBottom={20}>
          <div>Sidebar</div>
        </StickyBox>
        <div>Content</div>
      </div>
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-28
      • 2021-06-19
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-31
      • 2023-03-16
      相关资源
      最近更新 更多