조영찬
조영찬

Reputation: 1

I want to control progress bar

I want to control progress bar using variable

Like exp bar in games

can I get some example sources??

Ex: 1. HP : 10/10 [----------] <--Progressbar 2. Attacked by Monster [HP - 3] 3. HP : 7/10 [------- ]

Like this Sorry for bad English

Upvotes: 0

Views: 1121

Answers (2)

Loughmasta
Loughmasta

Reputation: 9

You can use Bootstrap progress bars and have a javascript var which then gets updated along with progress bar.

<!DOCTYPE html>
<html lang="en">
<head>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<script>
  var health = 100;
</script>
<div class="container">
  <h2>Colored Progress Bars</h2>
  <p>The contextual classes colors the progress bars:</p>
  <div class="progress">
    <div id="healthId" class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:100%">
      Health
    </div>
  </div>
  <button onclick="attackHealth()">Attack</button>
  <script>
function attackHealth() {
  health = health - 7;
  document.getElementById("healthId").setAttribute("style", "width:" + health + "%");
}
  </script>
</div>

</body>
</html>

Upvotes: 0

user5730329
user5730329

Reputation:

Here is a good example about that

var percentage = 75;
$(".progressbar").animate({
	  width: percentage + "%"
},1000);
.container{
  width: 500px;
  height: 50px;
  background: #ebebeb;
  margin-top: 5px;
  margin-left: 5px;
}

.progressbar{
  width: 0%;
  height: 50px;
  background: orange;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

<div class="container">
<div class="progressbar">

</div>
</div>

I have even build a website with something like that: http://m-andi.comyr.com/

Upvotes: 2

Related Questions