Может кто-нибудь сказать мне, почему мой веб-работник не работает?Я рисую анимированный холст, который хорошо работает.Но когда я изменяю его размер через текстовые поля, он перестает работать, пока не выполнится JavaScript.Теперь я создаю работника, который принимает на себя задачу изменения размера графики без остановки движения холста.Я хочу, чтобы он обновил значение скрытого поля, взяв значения текстовых полей, преобразовав их в строку, а затем присвоив результату значение скрытого поля.Для этого я делаю файлы.Я имею в виду отсутствие кода JavaScript в разметке HTML.файлы кодов следующие
/* Code that will be run by the worker */
function applyChanges(radius, size) {
return radius + "," + size;
}
/*
Add an event listener to the worker, this will be called when
the worker receives a message from the main page.
*/
this.onmessage = function (event) {
var data = event.data;
// Message sent by the worker to the main page.
postMessage(applyChanges(data.radius, data.size));
}
/* Worker's code */
// Create a new worker
var myWorker = new Worker("C:\applications\bb\scripts\setValues.js");
/*
Add a event listener to the worker, this will be called whenever the worker posts any message.
*/
myWorker.onmessage = function (event) {
document.getElementById().value = event.data;
};
// Register events for button.
document.getElementById("button").onclick = function () {
var circle = document.getElementById("tcircle");
var square = document.getElementById("tsquare");
var radius = circle.value;
var size = square.value;
// check if those are numerics
if (!isNaN(radius) && !isNaN(size)) {
// verify that the won't hide more the 1/4 of the circle.
if (radius >= size / Math.SQRT2) {
// since we are going to test scrolling and zooming, we are not going to set max values of radius and size.
message = { "tcircle": radius, "tsize": size };
// Message sent by the main page to the worker.
myWorker.postMessage(message);
}
else {
alert("The radius must not be less that: size/sqrt(2)");
}
}
else {
alert("Required numeric type!");
}
}
// Terminate the worker.
myWorker.terminate();