Progress bar

In this example below you will see how to do a Progress bar with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 025pro, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 025pro ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Progress bar</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <dic id="root">
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/025pro/progress-bar-dWyqxK */
.progress {
  height: 25px;
  width: 250px;
  border-radius: 25px;
  position: relative;
  background: #ccc;
}
.progress .after {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  border-radius: 25px;
  background: url(https://sitn.bet/assets/eff.png) #e91e63 repeat-x;
  background-size: 25px 25px;
  transition: width linear .2s;
}

.progress.animate .after {
  animation-name: progress;
  animation-duration: 1s;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

@keyframes progress {
  from {
    background-position: 0%;
  }
  to {
    background-position: -25px;
  }
}


/*Downloaded from https://www.codeseek.co/025pro/progress-bar-dWyqxK */
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Progress = function (_React$Component) {
  _inherits(Progress, _React$Component);

  function Progress(props) {
    _classCallCheck(this, Progress);

    var _this = _possibleConstructorReturn(this, (Progress.__proto__ || Object.getPrototypeOf(Progress)).call(this, props));

    _this.max = props.max;
    _this.width = props.width;
    if (props.current > _this.max) {
      throw "Current progress cannot be higher than max value";
    }
    _this.state = {
      current: props.current,
      animate: props.animate || false
    };
    return _this;
  }

  _createClass(Progress, [{
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      if (nextProps.current > this.max) {
        throw "Current progress cannot be higher than max value";
      }
      this.setState({
        current: nextProps.current,
        animate: nextProps.animate || false
      });
    }
  }, {
    key: "getProgressWidth",
    value: function getProgressWidth() {
      var j = this.state.current / this.max * this.width;
      console.log(j);
      return j + "px";
    }
  }, {
    key: "getProgressClass",
    value: function getProgressClass() {
      return "progress" + (this.state.animate ? " animate" : "");
    }
  }, {
    key: "render",
    value: function render() {
      return React.createElement(
        "div",
        { className: this.getProgressClass(), style: { width: this.width + "px" } },
        React.createElement("div", { className: "after", style: { width: this.getProgressWidth() } })
      );
    }
  }]);

  return Progress;
}(React.Component);

/* ==== DEMO ==== */


var current = 0;
var step = 5;
var max = 100;
var animate = true;
var interval = setInterval(function () {
  if (current + step >= max) animate = false;
  ReactDOM.render(React.createElement(Progress, { max: max, current: current, width: 500, animate: animate }), document.getElementById('root'));
  current += step;
  if (current > 100) clearInterval(interval);
}, 300);

Comments