Skip to content

Instantly share code, notes, and snippets.

@ryndel
Last active December 22, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryndel/6512126 to your computer and use it in GitHub Desktop.
Save ryndel/6512126 to your computer and use it in GitHub Desktop.
A simple html clickable meter
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Meter</title>
<style>
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
div#weight {
padding: 10px;
background-color: #fafafa;
width: 220px;
}
div.meter-container {
width: 0%;
position: relative;
background-color: #0F0;
height: 15px;
background-color: #428bca;
}
ul.meter {
position: absolute;
top: 0;
left: 0;
margin: 0;
padding: 0;
list-style-type: none;
width: 200px;
background-color: rgba(0,0,0,.1)
}
ul.meter li {
float: left;
width: 10%;
height: 15px;
border: 1px solid #fff;
border-collapse: collapse;
}
</style>
</head>
<body>
<div id="weight">
<div class="meter-container">
<ul class="meter">
<li class="1"></li>
<li class="2"></li>
<li class="3"></li>
<li class="4"></li>
<li class="5"></li>
<li class="6"></li>
<li class="7"></li>
<li class="8"></li>
<li class="9"></li>
<li class="10"></li>
</ul>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js"></script>
<script>
$(document).ready(function() {
$(".meter li").click(function() {
var amt = $(this).attr('class') * 10;
$(this).closest(".meter-container").css( "width", amt +"%" );
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment