Drawing animated arc with pure CSS

后端 未结 6 1781
挽巷
挽巷 2020-12-30 06:22

I know it is possible to draw and animate arcs in svg and canvas. However, is it possible in css?

I have created an arc using the following method:

.         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 06:52

    If you need sole CSS3, then you can set a width+height, set border-radius to 100%, disable the extra borders (use only 1 or 2) and add some good pixels to it.

    Then you can animate using animate: time animation ease timingFunction; Declare the animation itself using @-prefix-keyframes { . . . } (Eh yea, looks like most browser engines require prefix for this one, chrome does :S) I think I might have something close to what you mean:

    .qLoader2 {
      border: 4px solid blue;
      width: 10vw;
      height: 10vw;
      width: 72px;
      height: 72px;
      position: absolute;
      top: 12vh;
      right: 45vw;
      left: 45vw;
      background: white;
      opacity: 0.45;
      border-right: none;
      border-top: none;
      border-left: none;
      z-index: 2000;
      background-color: transparent;
      border-radius: 100%;
      transform: rotateZ(0);
      -webkit-animation: spin 2s linear infinite;
      animation: spin 2s linear infinite;
    }
    
    
    /* @-moz-keyframes spin {  . . . } */
    
    
    /* @-ms-keyframes spin {  . . . } */
    
    
    /* @-o-keyframes spin { . . . } */
    
    @-webkit-keyframes spin {
      from {
        transform: rotateZ(0deg) scale(1);
      }
      50% {
        transform: rotateZ(540deg) scale(0.9);
        border-color: #0099ff;
      }
      to {
        transform: rotateZ(1080deg) scale(1);
      }
    }
    
    @keyframes spin {
      from {
        transform: rotateZ(0deg) scale(1);
      }
      50% {
        transform: rotateZ(540deg) scale(0.9);
        border-color: #0099ff;
      }
      to {
        transform: rotateZ(1080deg) scale(1);
      }
    }

    On JSFiddle

    Feel free to use and modify. Alternatively you could check something with SVG it's fairly decent as well and supported by most nowadays browsers.

提交回复
热议问题