<doctype html>
<html>
<head>
<style>
#snapshotCanvas {
width: 307px;
height: 250px;
background: rgba(255,255,255,0.5);
border: 1px solid #ccc;
}
#output {
width: 307px;
height: 250px;
background: rgba(255,255,255,0.5);
border: 0px solid #ccc;
}
#screenshot-stream {
width: initial;
height: initial;
}
#screenshot {
vertical-align: top;
}
.blur {
filter: blur(3px);
filter: blur(3px);
filter: blur(3px);
filter: blur(3px);
filter: blur(3px);
}
.brightness {
filter: brightness(5);
filter: brightness(5);
filter: brightness(5);
filter: brightness(5);
filter: brightness(5);
}
.contrast {
filter: contrast(8);
filter: contrast(8);
filter: contrast(8);
filter: contrast(8);
filter: contrast(8);
}
.hue-rotate {
filter: hue-rotate(90deg);
filter: hue-rotate(90deg);
filter: hue-rotate(90deg);
filter: hue-rotate(90deg);
filter: hue-rotate(90deg);
}
.hue-rotate2 {
filter: hue-rotate(180deg);
filter: hue-rotate(180deg);
filter: hue-rotate(180deg);
filter: hue-rotate(180deg);
filter: hue-rotate(180deg);
}
.hue-rotate3 {
filter: hue-rotate(270deg);
filter: hue-rotate(270deg);
filter: hue-rotate(270deg);
filter: hue-rotate(270deg);
filter: hue-rotate(270deg);
}
.saturate {
filter: saturate(10);
filter: saturate(10);
filter: saturate(10);
filter: saturate(10);
filter: saturate(10);
}
.grayscale {
filter: grayscale(1);
filter: grayscale(1);
filter: grayscale(1);
filter: grayscale(1);
filter: grayscale(1);
}
.sepia {
filter: sepia(1);
filter: sepia(1);
filter: sepia(1);
filter: sepia(1);
filter: sepia(1);
}
.invert {
filter: invert(1);
filter: invert(1)
filter: invert(1)
filter: invert(1)
filter: invert(1)
}
</style>
</head>
<body>
<video id="output" width="200" height="200" autoplay>Put your fallback message here.</video>
<canvas id="snapshotCanvas" width="200" height="200"></canvas><p>
<button id="startVideoCapture">Start Capture</button>
<button id="stopVideoCapture">Stop Capture</button>
<button id="takeSnapshot">Take snapshot</button>
<script>
var n = navigator, is_webkit = false;
var vido = document.getElementById('output');
var canvas = document.querySelector('#snapshotCanvas');
var context = canvas.getContext('2d');
var is_mozilla=false;
document.querySelector('#stopVideoCapture').addEventListener('click', function(e) {
output.pause();
}, false);
document.querySelector('#startVideoCapture').addEventListener('click', function(e) {
startCapture();
}, false);
document.querySelector('#takeSnapshot').addEventListener('click', function(e) {
takeSnapshot();
}, false);
function onSuccess(stream) {
var video = document.getElementById('output'),
source;
video.autoplay = true;
var source;
if (!is_webkit) {
source = stream;
}
else {
source = window.webkitURL.createObjectURL(stream);
}
if (is_mozilla) {
video.mozSrcObject = source;
} else {
video.src = source;
}
}
function onError() {
// getUserMedia API not supported, or another application is using the webcam !
}
function startCapture() {
if (navigator.mozGetUserMedia) {
is_mozilla = true;
navigator.mozGetUserMedia({video:true, audio:false}, onSuccess, onError);
}
else if (navigator.getUserMedia) {
navigator.getUserMedia({video:true, audio:false}, onSuccess, onError);
}
else if (navigator.webkitGetUserMedia) {
is_webkit = true;
navigator.webkitGetUserMedia({video:true, audio:false}, onSuccess, onError);
}
}
takeSnapshot = function() {
context.drawImage(output, 0, 0, canvas.width, canvas.height);
}
var idx = 0;
var filters = [
'grayscale',
'sepia',
'blur',
'brightness',
'contrast',
'hue-rotate', 'hue-rotate2', 'hue-rotate3',
'saturate',
'invert',
''
];
function changeFilter(e) {
var el = e.target;
el.className = '';
var effect = filters[idx++ % filters.length];
if (effect) {
el.classList.add(effect);
}
}
output.addEventListener('click', changeFilter, false);
</script>
</body>
</html>
if (document.getElementById('hello')) {
document.getElementById('hello').innerHTML = 'Hello World - this was inserted using JavaScript';
}
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. |