0
我正在研究这个小绘图应用程序类型的东西,但它在Firefox中不起作用。它虽然在Chrome中工作正常。这里是javascript,然后我只是在HTML中有一个普通的旧画布元素。任何帮助表示赞赏!画布绘图应用程序不会在Firefox中工作
/* FOR THE DRAWING APPLICATION */
/* =========================== */
var canvasMouse, contextMouse;
var started = false;
var x, y;
function initMouse() {
// Get the drawing canvas
canvasMouse = document.getElementById('drawing');
contextMouse = canvasMouse.getContext('2d');
// Add some event listeners so we can figure out what's happening
// and run a few functions when they are executed.
canvasMouse.addEventListener('mousemove', mousemovement, false);
canvasMouse.addEventListener('mousedown', mouseclick, false);
canvasMouse.addEventListener('mouseup', mouseunclick, false);
}
function mouseclick() {
// When the mouse is clicked. Change started to true and move
// the initial position to the position of the mouse
contextMouse.beginPath();
contextMouse.moveTo(x, y);
started = true;
}
function mousemovement(e) {
// Get moust position
x = e.offsetX;
y = e.offsetY;
// If started is true, then draw a line
if(started) {
contextMouse.lineTo(x, y);
contextMouse.stroke();
}
}
function mouseunclick() {
// Change started to false when the user unclicks the mouse
if(started) {
started = false;
}
}
任何想法?
canvas元素有点新鲜和挑剔,可以跨越不同的浏览器。究竟是什么不起作用? – kevin628
以及没有什么作品。该图不起作用。它应该是一个简单的绘图应用程序,但它不会画! – Johnny