Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to apply sticky to vertical and horizontal scrolling. #555

Open
sin-to-jin opened this issue Aug 13, 2021 · 2 comments
Open

I want to apply sticky to vertical and horizontal scrolling. #555

sin-to-jin opened this issue Aug 13, 2021 · 2 comments

Comments

@sin-to-jin
Copy link

For example, with code like sample code, in a section such as a table, you can fix the header row when scrolling horizontally. Then, when you scroll vertically, can you make the header row follow (sticky) ?

Of course, I can use js to get the value when the scroll position changes and control the header using transform, ect., but I don't want to handle self-code if possible. thanks.

If there is no such feature in this library, I will try to change the UI in js, but if there is, I would appreciate it if you could let me know.

@sin-to-jin sin-to-jin changed the title Fix the first line of horizontal scrolling and fix the header line of vertical scrolling. I want to apply sticky to vertical and horizontal scrolling. Aug 13, 2021
@redonkulus
Copy link
Contributor

I haven't tried this myself, you can certainly try it and see what functionality is missing

@sin-to-jin
Copy link
Author

sin-to-jin commented Aug 13, 2021

import React from 'react';
import { ReactElement } from 'react';
import Sticky from 'react-stickynode';

const Test = (): ReactElement => {
  return (
    <div style={{ overflow: 'hidden', marginTop: '100px' }}>
      <Sticky className="navbar sections">
        <h1 style={{ fontSize: '60px', marginBottom: '60px' }}>Nav</h1>
      </Sticky>
      <h2 style={{ fontSize: '30px' }}>Hello, World</h2>

      <div style={{ overflowX: 'auto' }}>
        <Sticky className="header sections">
          {[...Array(8)].map((_, i) => {
            return (
              <Sticky key={i}>
                <div
                  style={{
                    display: 'flex',
                    flexDirection: 'row',
                    fontSize: '25px',
                    background: 'red',
                  }}
                >
                  <div>{`Header: ${i}`}</div>
                </div>
              </Sticky>
            );
          })}
        </Sticky>

        <div
          style={{
            display: 'flex',
            flexDirection: 'column',
            fontSize: '25px',
          }}
        >
          {[...Array(100)].map((_, i2) => {
            return (
              <div key={`row-${i2}`} style={{ display: 'flex' }}>
                {[...Array(8)].map((_, i) => {
                  return i === 0 || i === 1 ? (
                    <Sticky key={i2} className="data sections">
                      <div key={i}>{`Content: ${i2} / ${i}`}</div>
                    </Sticky>
                  ) : (
                    <div key={i}>{`Content: ${i2} / ${i}`}</div>
                  );
                })}
              </div>
            );
          })}
        </div>
      </div>
    </div>
  );
};

export default Test;

The navbar and header sections were followed by vertical scrolling. However, the sticky in the data sections did not respond to horizontal scrolling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants