Circle loading animation

后端 未结 5 1100
天命终不由人
天命终不由人 2020-12-07 14:05

I\'m trying to create Apple\'s OS X circle loading animation.

\"enter

What I h

5条回答
  •  清歌不尽
    2020-12-07 14:57

    I had to do this with a mixture of SVG and CSS gradients which i know is against the request but is what i know. I used some of your original code, mostly the SVG parts for the propeller shapes.

    The radial gradient is made using 12 li elements.

    .wheel,
    .umbrella,
    .color {
      content: "";
      position: absolute;
      border-radius: 50%;
      width: 15em;
      height: 15em;
      margin: 0;
      padding: 0;
    }
    .wheel {
      overflow: hidden;
      width: 15em;
      height: 15em;
      position: relative;
    }
    .umbrella {
      position: relative;
      -webkit-transform: scale(1.35);
    }
    .color,
    .color:nth-child(n+7):after {
      clip: rect(0, 15em, 15em, 7.5em);
    }
    .color:after,
    .color:nth-child(n+7) {
      content: "";
      position: absolute;
      border-radius: 50%;
      left: calc(50% - 7.5em);
      top: calc(50% - 7.5em);
      width: 15em;
      height: 15em;
      clip: rect(0, 7.5em, 15em, 0);
    }
    .color:nth-child(1):after {
      background-color: #9ED110;
      transform: rotate(30deg);
      z-index: 12;
    }
    .color:nth-child(2):after {
      background-color: #50B517;
      transform: rotate(60deg);
      z-index: 11;
    }
    .color:nth-child(3):after {
      background-color: #179067;
      transform: rotate(90deg);
      z-index: 10;
    }
    .color:nth-child(4):after {
      background-color: #476EAF;
      transform: rotate(120deg);
      z-index: 9;
    }
    .color:nth-child(5):after {
      background-color: #9f49ac;
      transform: rotate(150deg);
      z-index: 8;
    }
    .color:nth-child(6):after {
      background-color: #CC42A2;
      transform: rotate(180deg);
      z-index: 7;
    }
    .color:nth-child(7):after {
      background-color: #FF3BA7;
      transform: rotate(180deg);
    }
    .color:nth-child(8):after {
      background-color: #FF5800;
      transform: rotate(210deg);
    }
    .color:nth-child(9):after {
      background-color: #FF8100;
      transform: rotate(240deg);
    }
    .color:nth-child(10):after {
      background-color: #FEAC00;
      transform: rotate(270deg);
    }
    .color:nth-child(11):after {
      background-color: #FFCC00;
      transform: rotate(300deg);
    }
    .color:nth-child(12):after {
      background-color: #EDE604;
      transform: rotate(330deg);
    }


    These 12 elements can then be blurred together to form the smooth gradient.

    I then animated the spin parts to make the effect you require.

    var rotation = 0;
    
    $(document).ready(function() {
      setInterval(function() {
        rotation += 1;
        $('.wheel svg').css({
          'transform': 'rotate(' + rotation + 'deg)'
        });;
      }, 10);
    });
    .wheel,
    .umbrella,
    .color {
      content: "";
      position: absolute;
      border-radius: 50%;
      width: 15em;
      height: 15em;
      margin: 0;
      padding: 0;
    }
    .wheel {
      overflow: hidden;
      width: 15em;
      height: 15em;
      position: relative;
    }
    .umbrella {
      position: relative;
      filter: blur(.75em);
      -webkit-filter: blur(.75em);
      -moz-filter: blur(.75em);
      -o-filter: blur(.75em);
      -ms-filter: blur(.75em);
      filter: url(#blur);
      filter: progid: DXImageTransform.Microsoft.Blur(PixelRadius='.75');
      -webkit-transform: scale(1.35);
    }
    .color,
    .color:nth-child(n+7):after {
      clip: rect(0, 15em, 15em, 7.5em);
    }
    .color:after,
    .color:nth-child(n+7) {
      content: "";
      position: absolute;
      border-radius: 50%;
      left: calc(50% - 7.5em);
      top: calc(50% - 7.5em);
      width: 15em;
      height: 15em;
      clip: rect(0, 7.5em, 15em, 0);
    }
    .color:nth-child(1):after {
      background-color: #9ED110;
      transform: rotate(30deg);
      z-index: 12;
    }
    .color:nth-child(2):after {
      background-color: #50B517;
      transform: rotate(60deg);
      z-index: 11;
    }
    .color:nth-child(3):after {
      background-color: #179067;
      transform: rotate(90deg);
      z-index: 10;
    }
    .color:nth-child(4):after {
      background-color: #476EAF;
      transform: rotate(120deg);
      z-index: 9;
    }
    .color:nth-child(5):after {
      background-color: #9f49ac;
      transform: rotate(150deg);
      z-index: 8;
    }
    .color:nth-child(6):after {
      background-color: #CC42A2;
      transform: rotate(180deg);
      z-index: 7;
    }
    .color:nth-child(7):after {
      background-color: #FF3BA7;
      transform: rotate(180deg);
    }
    .color:nth-child(8):after {
      background-color: #FF5800;
      transform: rotate(210deg);
    }
    .color:nth-child(9):after {
      background-color: #FF8100;
      transform: rotate(240deg);
    }
    .color:nth-child(10):after {
      background-color: #FEAC00;
      transform: rotate(270deg);
    }
    .color:nth-child(11):after {
      background-color: #FFCC00;
      transform: rotate(300deg);
    }
    .color:nth-child(12):after {
      background-color: #EDE604;
      transform: rotate(330deg);
    }
    body {
      padding: 5px;
    }
    .wheel svg {
      position: absolute;
      top: 0;
      opacity: .5;
    }
    
    

    • Conical CSS Gradient

提交回复
热议问题