JSFiddle - React, Tailwind, and code Playground
by Raphael Quintao
HTML
<div id="teste1">Mouse Position</div>
<span id="teste2"></span>
<div class="ctr-circle">
<div class="ctr-volume-holder" data-percent="55">
<canvas class="ctr-volume-bar"></canvas>
</div>
</div>
CSS
body {
background-color: #555;
}
#teste1 {
position: absolute;
top: 0;
right: 0;
margin: 10px;
background-color: #e1e1e1;
padding: 5px 7px;
font-family: monospace;
white-space: pre;
}
.ctr-circle {
position: absolute;
display: flex;
width: 200px;
height: 200px;
margin: 20px;
padding: 0px;
top: 0;
left: 0;
border-radius: 50%;
box-shadow: inset 0 1px 1px 1px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 1);
background-color: #e1e1e1;
/* background-image: url("https://dl.dropboxusercontent.com/u/2345114/ts_banner.jpg"); */
background-size: cover;
overflow: hidden;
}
.ctr-volume-holder {
position: absolute;
//width: calc(100% - 10px);
width: 100%;
height: 100%;
bottom: 0;
margin: 0;
box-sizing: border-box;
background-color: #ff9900;
overflow: hidden;
left: 50%;
transform: translateX(-50%);
}
canvas.ctr-volume-bar {
position: absolute;
width: 100%;
height: 100%;
bottom: 0;
background-color: rgba(255, 0, 0, 0.7);
/* left:50%; */
/* transform: rotate(-45deg); */
}
span {
background-color: #e1e1e1;
right: 0;
bottom: 0;
color: #555;
position: absolute;
display: inline-block;
text-align: left;
font-size: 13px;
margin: 10px;
padding: 5px 7px;
white-space: pre;
font-family: monospace;
}
JavaScript
var teste = document.getElementById('teste1');
var debug = document.getElementById('teste2');
var Volume = {
holder: null,
canvas: null,
barSize: 8,
handlerSize: 14
};
Volume.holder = document.getElementsByClassName("ctr-volume-holder")[0];
Volume.canvas = Volume.holder.getElementsByClassName("ctr-volume-bar")[0];
createVolumeBar();
function createVolumeBar() {
var ctx = Volume.canvas.getContext('2d', {
antialias: true
});
var WIDTH = Volume.canvas.width = Volume.canvas.clientWidth;
var HEIGHT = Volume.canvas.height = Volume.canvas.clientHeight;
var percent = Volume.holder.getAttribute('data-percent') || 0;
percent = parseInt(percent + "");
var barSize = Volume.barSize;
var handle = {
radius: Volume.handlerSize,
x: 0.0,
y: 0.0
};
var mouse = {
x: 0,
y: 0
};
var margin = 0 + handle.radius/2;
var radius = (WIDTH - barSize*2 - margin*2) / 2;
var centerX = WIDTH / 2;
//var centerY = radius + barSize / 2 + margin / 2;
var centerY = margin + barSize;
//centerY *= 1+scale;
Volume.canvas.height = (radius + margin*2 + barSize*2) ;
Volume.canvas.style.height = Volume.canvas.height + 'px';
//Volume.canvas.width = (radius + margin*2 + barSize*2) ;
//Volume.canvas.style.width = Volume.canvas.width + 'px';
var step = Math.PI / 200;
ctx.translate(centerX, centerY);
ctx.beginPath();
//ctx.moveTo(radius, 40);
ctx.arc(0, 0, radius, 0.5, 2.5, false);
ctx.lineCap = 'round';
ctx.lineWidth = barSize;
//ctx.translate(centerX, centerY);
// line color
ctx.strokeStyle = 'black';
ctx.stroke();
var drawCircle = function(color, lineWidth, p) {
//p +=1;
var x = 0;
var y = 0;
ctx.save();
ctx.beginPath();
for (var i = 0.8; i < (Math.PI * p) - 0.8; i += step) {
x = 0 + radius * Math.cos(i) * (-1);
y = 0 +...