Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS radial / circular progress indicator with a transparent middle

Tags:

css

sass

I'd like to make a radial progress indicator with css that has it's middle circle transparent. See here: http://codepen.io/geedmo/pen/InFfd – it's a perfect example of what I want to do but the middle (.overlay) has background-color which overlays the bigger circle. However, I'd like to have it transparent (the bigger circle would have transparent middle too). How to do it?

<div class="wrap">

<div class="progress-radial progress-25">
  <div class="overlay">25%</div>
</div>

<div class="progress-radial progress-50">
  <div class="overlay">50%</div>
</div>

<div class="progress-radial progress-75">
  <div class="overlay">75%</div>
</div>

<div class="progress-radial progress-90">
  <div class="overlay">90%</div>
</div>

</div>

SASS:

// Colors
$barColor: tomato
$overlayColor: #fffde8
$backColor: #2f3439

@import url(http://fonts.googleapis.com/css?family=Noto+Sans)

body
  padding: 30px 0
  background-color: $backColor
  font-family: 'Noto Sans', sans-serif

.wrap
  width: 600px
  margin: 0 auto

/* -------------------------------------
 * Bar container
 * ------------------------------------- */
.progress-radial
  float: left
  margin-right: 30px
  position: relative
  width: 100px
  height: 100px
  border-radius: 50%
  border: 2px solid $backColor // remove gradient color


/* -------------------------------------
 * Optional centered circle w/text
 * ------------------------------------- */  
.progress-radial .overlay
  position: absolute
  width: 60px
  height: 60px
  background-color: $overlayColor
  border-radius: 50%
  margin-left: 20px
  margin-top: 20px
  text-align: center
  line-height: 60px
  font-size: 16px

/* -------------------------------------
 * Mixin for progress-% class
 * ------------------------------------- */

$step: 5 // step of % for created classes

$loops: round(100 / $step)
$increment: 360 / $loops
$half: round($loops / 2)
@for $i from 0 through $loops
  .progress-#{$i*$step}
    @if $i < $half
      $nextdeg: 90deg + ( $increment * $i )
      border-image: linear-gradient(90deg, $backColor 50%, transparent 50%, transparent), linear-gradient($nextdeg, $barColor 50%, $backColor 50%, $backColor)
    @else
      $nextdeg: -90deg + ( $increment * ( $i - $half ) )
      border-image: linear-gradient($nextdeg, $barColor 50%, transparent 50%, transparent), linear-gradient(270deg, $barColor 50%, $backColor 50%, $backColor)

This is the result I'd like to get:

result

like image 367
simPod Avatar asked Dec 18 '25 01:12

simPod


1 Answers

html code :

<div class="wrapper">
    <div class="pie spinner lightBlue"></div>
    <div class="pie filler lightBlue"></div>
    <div class="mask"></div>               
</div>

css code :

body {
    background-color: #f3f3f4;
}

.lightBlue {
    border: 10px solid #a8d2d2;
}

.wrapper {
    width: 250px;
    height: 250px;   
    margin: 10px auto;
    position: relative;
    background: white;
    background-color: #f3f3f4;
    -webkit-transition: width 0.5s, height 0.5s;
    transition: width 0.5s, height 0.5s;
    -webkit-animation: finalRota 2s 10s linear forwards;
    animation: finalRota 2s 10s linear forwards;
}

.wrapper .pie {
    width: 50%;
    height: 100%;
    position: absolute;
    background-color: radial-gradient(left center, circle, #00ccff 0px, #000088 100%);
    -webkit-transform-origin: 100% 50%;
    -ms-transform-origin: 100% 50%;
    transform-origin: 100% 50%;
}

.wrapper .spinner {
    border-radius: 100% 0 0 100% / 50% 0 0 50%;
    z-index: 200;
    background-color: radial-gradient(right center, circle, #00ccff 0px, #000088 100%);
    border-right: none;
    -webkit-animation: rota 10s linear forwards;
    animation: rota 10s linear forwards;
}

.wrapper .filler {
    border-radius: 0 100% 100% 0 / 0 50% 50% 0;
    left: 50%;
    border: 10px solid #8dbdbb;
    opacity: 0;
    z-index: 100;
    border-left: none;
    -webkit-animation: fill 10s steps(1, end) forwards;
    animation: fill 10s steps(1, end) forwards;
}

.wrapper .mask {
    width: 50%;
    height: 100%;
    position: absolute;
    background: inherit;
    opacity: 1;
    z-index: 300;
    -webkit-animation: mask 10s steps(1, end) forwards;
    animation: mask 10s steps(1, end) forwards;
}

@-webkit-keyframes opoFinalRota {
    100% {
        -webkit-transform: rotate(30deg);        
        -ms-transform: rotate(30deg);        
        transform: rotate(30deg);
    }
}

@keyframes opoFinalRota {
    100% {
        -webkit-transform: rotate(30deg);        
        -ms-transform: rotate(30deg);        
        transform: rotate(30deg);
    }
}
@-webkit-keyframes rota {
    0% {
        -webkit-transform: rotate(300deg);
        transform: rotate(300deg);
    }
    100% {
        -webkit-transform: rotate(60deg);
        transform: rotate(60deg);
    }
}
@keyframes rota {
    0% {
        -webkit-transform: rotate(300deg);
        transform: rotate(300deg);
    }
    100% {
        -webkit-transform: rotate(60deg);
        transform: rotate(60deg);
    }
}
@-webkit-keyframes mask {
    0% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}
@keyframes mask {
    0% {
        opacity: 1;
    }
    50%, 100% {
        opacity: 0;
    }
}
@-webkit-keyframes fill {
    0% {
        opacity: 0;
    }
    50%, 100% {
        opacity: 1;
    }
}
@keyframes fill {
    0% {
        opacity: 0;
    }
    50%, 100% {
        opacity: 1;
    }
}

and a demo : http://jsfiddle.net/usrs01ye/2/

enter image description here

like image 174
fizampou Avatar answered Dec 20 '25 22:12

fizampou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!