Drawing animated arc with pure CSS

后端 未结 6 1769
挽巷
挽巷 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:50

    EDIT: Using two arcs, you can have the animation draw cleanly from left-to-right AND have the background show through:

    http://jsfiddle.net/sPv4A/6/

    Vendor prefixes not included for CSS:

    .arcContain {
      width: 150px;
      height: 400px;
      position: relative;
      margin: 20px;
    }
    
    .arc {
      width: 150px;
      height: 400px;
      border-radius: 50%;
      border: 2px solid black;
      border-bottom: 2px solid transparent;
      position: absolute;
      top: 0;
      right: 0;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
    }
    
    .archideLeft .arc {
      top: auto;
      bottom: 0;
      right: auto;
      left: 0;
    }
    
    .archide {
      width: 50%;
      height: 0%;
      position: absolute;
      top: 0;
      right: 0;
      overflow: hidden;
      animation: appear 1.2s ease-in 1.2s forwards;
    }
    
    .archideLeft {
      top: auto;
      bottom: 0;
      right: auto;
      left: 0;
      animation: appear 1.2s ease-out forwards;
    }
    
    @keyframes appear {
      to {
        height: 100%;
      }
    }

    OLD ANSWER: Maybe using two child divs to cover it up, and then have them shrink away to reveal it:

    .arc {
      width: 150px;
      height: 400px;
      border-radius: 50%;
      border-right: 1px solid black;
      border-left: 1px solid black;
      border-top: 1px solid black;
      border-bottom: 1px solid white;
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      position: relative;
    }
    
    .arcInner {
      background: white;
      height: 402px;
      width: 77px;
      position: absolute;
    }
    
    .arcLeft {
      top: -2px;
      left: -2px;
      -webkit-transition: height 2s linear;
      -moz-transition: height 2s linear;
      -ms-transition: height 2s linear;
      -o-transition: height 2s linear;
      transition: height 2s linear;
    }
    
    .arcRight {
      bottom: 0;
      right: -2px;
      -webkit-transition: height 2s 2s linear;
      -moz-transition: height 2s 2s linear;
      -ms-transition: height 2s 2s linear;
      -o-transition: height 2s 2s linear;
      transition: height 2s 2s linear;
    }
    
    .appear .arcInner {
      height: 0;
    }

提交回复
热议问题