Getting web front-end to combat: skeleton css screen program implementation

advantage

  • Simple, no engineering, no puppeteer generate skeleton dom, nor the need for secondary development and maintenance
  • High degree of customization, like how do you how do
  • Not bloated, just to give you want

Shortcoming

  • Low degree of automation, need to manually add the backbone class dom
  • Synergistic demanding, not engineered to bind can Engineering

Thinking

Skeleton achieved by a pseudo-style elements to achieve dynamic switching operations by the skeleton and the page style

achieve

css portion (SCSS written)

By aftergenerating a pseudo-element skeleton form, and by absolutecovering onto the actual elements

专门建立的学习Q-q-u-n: 784-783-012 ,分享学习的方法和需要注意的小细节,不停更新最新的教程和学习技巧
(从零基础开始到前端项目实战教程,学习工具,全栈开发学习路线以及规划)
  .skt-loading {
    pointer-events: none; /* 加载中阻止事件 */
    .skeleton {
      position: relative;
      overflow: hidden;
      border: none !important;
      border-radius: 5px;
      background-color: transparent !important;
      background-image: none !important;
      &::after {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        z-index: 9;
        width: 100%;
        height: 100%;
        background-color: #EBF1F8;
        display: block;
      }

      /* 下面这部分都是自定义的,看需求修改 */
      &:not(.not-round)::after {
        border-radius: 4px;
      }
      &:not(.not-before)::before {
        position: absolute;
        top: 0;
        width: 30%;
        height: 100%;
        content: "";
        background: linear-gradient(to right,rgba(255,255,255,0) 0,
            rgba(255,255,255,.3) 50%,rgba(255,255,255,0) 100%);
        transform: skewX(-45deg);
        z-index: 99;
        animation: skeleton-ani 1s ease infinite;
        display: block;
      }
      &.badge {
        &::after {
          background-color: #F8FAFC;
        }
      }
    }
  }

  @keyframes skeleton-ani { /* 骨架屏动画 */
    from {
      left: -100%;
    }
    to {
      left: 150%;
    }
  }

html part

You only need to add on elements considered reasonable size skeleton skeletonclass can

js part

Control the skt-loadingswitching of the class

Caution

  • after pseudo-element container element can not be inserted into a non inputimg like, if you need to add skleton, it is necessary to add a layer enveloping element
  • Like vuereact for data-driven pages you need to have a mock data to generate dom

Guess you like

Origin blog.51cto.com/14592820/2463910