Skip to content
Loding Bar프로젝트

Replacing the Old Loading Bar with a Skeleton UI

1 min readProjectsMoved from my Tistory blogRead the Korean original

I built a skeleton UI myself and replaced what used to be shown with a loading bar.

I replaced it because I wanted to show users a more natural UI than the old loading bar.

Here is the code I wrote.

jsx
<Container>
      <Wrapper>
        {Array.from({ length: 6 }).map((_, index) => {
          return (
            <Box key={index}>
              <ImgBox />
              <ContentBox>
                <ItemBox>
                  <div>
                    <TopBox />
                    <BottomBox />
                  </div>
                  <img style={{ scale: '0.7' }} src={arrowImg} alt="arrowImg" />
                  <div>
                    <TopBox />
                    <BottomBox />
                  </div>
                </ItemBox>
                <ItemBox style={{ marginTop: '1.5rem' }}>
                  <div>
                    <TopBox />
                    <BottomBox />
                  </div>
                  <div>
                    <TopBox />
                    <BottomBox />
                  </div>
                </ItemBox>
                <PriceBox>
                  <div />
                </PriceBox>
                <CommentBox>
                  <div />
                  <div />
                </CommentBox>
                <ButtonBox>
                  <div />
                </ButtonBox>
              </ContentBox>
            </Box>
          );
        })}
      </Wrapper>
    </Container>
js
const loading = keyframes`{
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}`;

const Container = styled.div`
  padding-top: 27rem;
  width: 100%;
  display: flex;
  justify-content: center;
`;

const Wrapper = styled.div`
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;

  @media screen and (max-width: 599px) {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
  }
`;

const Box = styled.div`
  width: 35rem;
  height: 50rem;
  border: 1px solid rgb(217, 217, 217);
  border-radius: 18px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;

  @media screen and (max-width: 599px) {
    width: 90%;
  }
`;

const ImgBox = styled.div`
  height: 17rem;
  background: #f4f4f4;
  background-size: 200% 100%;
  animation: ${loading} 2.5s infinite;
`;

const ContentBox = styled.div`
  padding: 25px 25px 30px;
`;

const ItemBox = styled.div`
  display: flex;
  justify-content: space-between;
  align-items: center;

  & > div {
    width: 33%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
`;

const TopBox = styled.div`
  height: 1.5rem;
  border-radius: 1rem;
  background: #f4f4f4;
  background-size: 200% 100%;
  animation: ${loading} 2.5s infinite;
`;

const BottomBox = styled.div`
  height: 3rem;
  background: #f4f4f4;
  background-size: 200% 100%;
  animation: ${loading} 2.5s infinite;
`;

const PriceBox = styled.div`
  display: flex;
  justify-content: flex-end;
  margin-top: 2rem;

  & > div {
    width: 12rem;
    height: 3.5rem;
    border-radius: 1rem;
    background: #f4f4f4;
    background-size: 200% 100%;
    animation: ${loading} 2.5s infinite;
  }
`;

const CommentBox = styled.div`
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;

  & > div {
    height: 1.3rem;
    border-radius: 1rem;
    background: #f4f4f4;
    background-size: 200% 100%;
    animation: ${loading} 2.5s infinite;
  }

  & > div:first-child {
    width: 13rem;
  }

  & > div:last-child {
    width: 17rem;
  }
`;

const ButtonBox = styled.div`
  display: flex;
  justify-content: center;
  height: 4rem;
  margin-top: 2rem;

  & > div {
    width: 100%;
    border-radius: 1rem;
    background: #f4f4f4;
    background-size: 200% 100%;
    animation: ${loading} 2.5s infinite;
  }
`;​
  • #Loading Bar
  • #Skeleton UI

More in Projects