Creating a dynamic Tank level/meter using html and css

后端 未结 3 2006
遇见更好的自我
遇见更好的自我 2020-12-16 23:33

I am currently having problems creating a \'tank gauging system\' within my project. I am using MVC and the by using the following markup, I have achieved this:

3条回答
  •  时光说笑
    2020-12-17 00:29

    I think I have achieved the requested, by playing around with positioning (absolute will respect the parent block element with position relative or absolute - so it is easier to just use bottom: 0 - also that makes the div to increase its height from botton to top automatically)

    html

    css file:

    .tk {
        position:relative;
        width:40%; 
        height:100px;
        padding-top:40px;
        margin: 0 auto;
        background:rgba(56,56,56,0.8);
        border-radius: 100%/40px;
        border-bottom:3px solid #000;
        text-align:center;
        z-index:1;
        overflow:hidden;
        }
        
    .lq {
      position: absolute;
      background:rgba(128,128,128,0.99);
      width: 100%;
      height:0;
      bottom: 0;
      border-radius:100%/40px;
      border-bottom:3px solid #000;
    }
    
    
    .ring {
      position: absolute;
      border-radius:100%;
      top: 0;
      width: 100%;
      height:40%;
      content: '';
      border:1px solid #000;
    }
        
    .text {
      display: block;
      position:absolute;
      top: 45%;
      left: 45%;
      z-index: 1;
    }
    

    js file (with jquery):

    var quantity = amount;
    $(this).find('.lq').animate({'height' : parseInt(amount) + '%'},1000);
      $('.ring').css({height : 100 - amount + 10 + '%'});
      $('.text').text(quantity  + '%'); 
      });
      $('.text').each(function(){
        var $this = $(this);
         jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
        duration: 1000,
        easing: 'swing',
        step: function () {
          $this.text(Math.ceil(this.Counter) + "%");
        }
      });
      });
    });
    

    https://jsfiddle.net/DimK10/oqfz56ys/72/

提交回复
热议问题