欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

html5 畫板鉛筆的代碼

錢諍諍2年前6瀏覽0評論

HTML5畫板可以通過使用canvas元素和JavaScript來創建一個優雅而富有創意的畫布。在這種情況下,我們可以使用HTML5畫板鉛筆,它可以幫助我們在Users界面上快速而可靠地繪制對象。

var canvas,context;
var painting=false;
var lastX,lastY;
function init(){
canvas=document.getElementById('drawing-area');
context=canvas.getContext('2d');
context.lineWidth=5;
context.lineJoin='round';
context.lineCap='round';
context.strokeStyle='blue';
addEventHandler(canvas,'mousedown',function(e){
var mouseX=e.pageX-canvas.offsetLeft;
var mouseY=e.pageY-canvas.offsetTop;
painting=true;
addClick(mouseX,mouseY,false);
draw();
});
addEventHandler(canvas,'mousemove',function(e){
if(painting){
addClick(e.pageX-canvas.offsetLeft,e.pageY-canvas.offsetTop,true);
draw();
}
});
addEventHandler(canvas,'mouseup',function(e){
painting=false;
});
addEventHandler(canvas,'mouseleave',function(e){
painting=false;
});
}
function addEventHandler(obj,eventName,handler){
if(obj.addEventListener){
obj.addEventListener(eventName,handler,false);
} else if(obj.attachEvent){
obj.attachEvent('on'+eventName,handler);
} else {
obj['on'+eventName]=handler;
}
}
function addClick(x,y,drawing){
clickX.push(x);
clickY.push(y);
clickDrag.push(drawing);
}
function draw(){
context.clearRect(0,0,canvas.width,canvas.height); // Clears the canvas
context.beginPath();
context.moveTo(clickX[0], clickY[0]);
for(var i=1; i

在這段HTML5畫板鉛筆代碼中,我們定義了一系列事件處理程序,以便在用戶輸入新繪畫之后呈現出更完整的畫布。