Portál AbcLinuxu, 29. října 2025 10:34
var start = function () {
isRuns = true;
$('#pageMainImgDiv').hide();
nahravej();
};
var stop = function () {
// vynechan dialog ohledne ukonceni a dalsi akce ohledne manipulace s prvky na html strance
isRuns = false;
$('#pageMainImgDiv').show();
};
var nahravej = function () {
var timing = 5000;
var newSrc = "mujImage.png";
var img = new Image();
img.src = 'images/' + newSrc;
img.onload = function () {
var canvas = document.getElementById('mainCanvas');
var context = canvas.getContext('2d');
context.canvas.width = window.innerWidth;
context.canvas.height = window.innerHeight;
var x = (canvas.width - img.width ) * 0.5;
var y = (canvas.height - img.height) * 0.5;
img.width = img.width * 0.50;
img.height = img.height * 0.50;
context.drawImage(img, x, y);
if (isRuns) {
setTimeout(function () {
console.log('Probiha timer');
context.clearRect(0, 0, canvas.width, canvas.height);
var res = prompt("Vlož čas", "5");
if (isNaN(res)) {
alert('Chyba není číslo!');
} else {
console.log('Vlozeno ' + res);
nahravej();
}
}, timing);
}else {
context.clearRect(0, 0, canvas.width, canvas.height);
}
};
}
};
Řešení dotazu:
var id=window.setTimeout(...);S tým id sa to potom dá zrušiť volaním clearTimeout():
window.clearTimeout(id);
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.