<html>
<head>
<meta name="description" content="jquery-circle-progress: catching clicks">
<meta charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
<title>jquery-circle-progress customization: arc layout</title>
</head>
<body>
<div class="circle" id="circle-cl">
click
</div>
<div class="circle" id="circle-md">
mousedown
</div>
<div class="circle" id="circle-mm">
mousemove
</div>
<div class="circle" id="circle-dr">
dragging
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://rawgit.com/kottenator/jquery-circle-progress/1.1.3/dist/circle-progress.js"></script>
</body>
</html>
body {
text-align: center;
padding-top: 150px;
font: 16px/1.5 Lato, sans-serif;
}
.circle {
display: inline-block;
margin: 10px;
}
.circle canvas {
display: block;
}
;(function() {
var _originalInit = $.circleProgress.defaults.init;
$.circleProgress.defaults.init = function() {
_originalInit.apply(this, arguments);
this.handleEvents();
};
$.circleProgress.defaults.circleThreshold = 15;
$.circleProgress.defaults.events = ['click', 'mousedown', 'mouseup', 'mousemove'];
$.circleProgress.defaults.handleEvents = function() {
var self = this,
canvas = $(this.canvas);
canvas.on(this.events.join(' '), function(e) {
var offset = canvas.offset();
var r = self.size / 2,
x = e.pageX - offset.left - r, // translate coords ⏎
y = e.pageY - offset.top - r, // to the circle center
s = Math.sqrt(x * x + y * y), // calculate distance from center
t = self.circleThreshold; // add some "threshold"
// chech if the event has happened in the circle area
if (s >= r - self.getThickness() - t && s <= r + t) {
var m = (y > 0) ? 1 : -1, // sign modificator ⏎
a = m * Math.acos(x / s); // for current angle
// translate startAngle to [0, 2 * π] range
var sa = self.startAngle,
π = Math.PI; // start angle
sa = sa % (2 * π);
sa = sa < 0 ? 2 * π + sa : sa;
// calculate circle value for the event
var v = (a - sa) / (2 * π);
v = (v < 0) ? v + 1 : v;
self.el.trigger('circle-' + e.type, [v, x, y, a]);
}
});
};
})();
var config = {
size: 150,
value: 0.7,
startAngle: -Math.PI
};
function setValue(e, v) {
var instance = $(this).data('circle-progress');
$(instance.canvas).stop(true, true);
instance.drawFrame(v);
}
$('#circle-cl').circleProgress(config).on('circle-click', setValue);
$('#circle-md').circleProgress(config).on('circle-mousedown', setValue);
$('#circle-mm').circleProgress(config).on('circle-mousemove', setValue);
var customCircle = $('#circle-dr').circleProgress(config)
.on('circle-mousedown', function(e, v) {
$(this).data('circle-progress').dragging = true;
setValue.call(this, e, v);
})
.on('circle-mouseup', function(e, v) {
$(this).data('circle-progress').dragging = false;
})
.on('circle-mousemove', function(e, v) {
if ($(this).data('circle-progress').dragging) {
setValue.call(this, e, v);
}
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |