39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
|
/* Copyright (C) 2007 Richard Atterer, richard©atterer.net
|
||
|
This program is free software; you can redistribute it and/or modify it
|
||
|
under the terms of the GNU General Public License, version 2. See the file
|
||
|
COPYING for details. */
|
||
|
|
||
|
var imageNr = 0; // Serial number of current image
|
||
|
var finished = new Array(); // References to img objects which have finished downloading
|
||
|
var paused = false;
|
||
|
|
||
|
function createImageLayer() {
|
||
|
var img = new Image();
|
||
|
img.style.position = "absolute";
|
||
|
img.style.zIndex = -1;
|
||
|
img.style.width = "400px";
|
||
|
img.style.height = "320px";
|
||
|
img.onload = imageOnload;
|
||
|
img.onclick = imageOnclick;
|
||
|
img.src = "http://fotokiste:8081/?action=snapshot&n=" + (++imageNr);
|
||
|
var webcam = document.getElementById("live_pic");
|
||
|
webcam.insertBefore(img, webcam.firstChild);
|
||
|
}
|
||
|
|
||
|
// Two layers are always present (except at the very beginning), to avoid flicker
|
||
|
function imageOnload() {
|
||
|
this.style.zIndex = imageNr; // Image finished, bring to front!
|
||
|
while (1 < finished.length) {
|
||
|
var del = finished.shift(); // Delete old image(s) from document
|
||
|
del.parentNode.removeChild(del);
|
||
|
}
|
||
|
finished.push(this);
|
||
|
if (!paused) createImageLayer();
|
||
|
}
|
||
|
|
||
|
function imageOnclick() { // Clicking on the image will pause the stream
|
||
|
paused = !paused;
|
||
|
if (!paused) createImageLayer();
|
||
|
}
|
||
|
|