<html>
<head>
<style>
canvas, img {
background-color: #FFFFFF;
position: absolute;
top: 0px;
left: 0px;
z-index: 100;
background-image: url('http://www.userlogos.org/files/logos/pek/stackoverflow2.png');
background-position: center;
background-repeat: no-repeat;
}
?
</style>
</head>
<body>
<canvas width="1024" height="768"></canvas>
</body>
</html>
var canvas = document.getElementsByTagName('canvas')[0];
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var ctx = canvas.getContext('2d'),
cx = -100,
cy = canvas.height / 2,
r = 100,
R_MAX = 400;
ctx.fillstyle = '#000';
var goingright = true;
var zooming = false;
function draw() {
if(goingright) {
cx += 4;
} else if(zooming) {
r += 4;
} else {
cx -= 4;
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.save();
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(context.canvas.width, 0);
ctx.lineTo(context.canvas.width, context.canvas.height);
ctx.lineTo(0, context.canvas.height);
ctx.closePath();
ctx.arc(context.canvas.width / 2, context.canvas.height / 2, 50, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
/*ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(canvas.width, 0);
ctx.lineTo(canvas.width, canvas.height);
ctx.lineTo(0, canvas.height);
ctx.closePath();
ctx.moveTo(cx + r, cy);
ctx.arc(cx, cy, r, 0, Math.PI*2, true);
// check if to draw a fixed circle, every 200 pixels for 100 pixels
if(goingright && cx % 200 < 100) {
ctx.moveTo(cx - cx % 200 + r, cy);
ctx.arc(cx - cx % 200, cy, r, 0, Math.PI*2, true);
}
ctx.closePath();
ctx.clip();*/
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore();
// when the circle is on the right side, go left
if(cx > canvas.width + r * 1.8) {
goingright = false;
if(r == 100) {
r = 180;
}
// when the circle is bigger than the hight of the canvas, remove and show content
} else if (r > canvas.height) {
// done
// when the circle is going left and is in the middle, zoom in
} else if (cx < canvas.width / 2 && !goingright) {
zooming = true;
}
setTimeout(draw, 7);
}
draw();
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. |