Dieser Artikel teilt einen von HTML5 -Leinwand implementierten Bildausschussercode für Ihre Referenz. Der spezifische Inhalt ist wie folgt
<! DocType html> <html> <head> <meta charset = "utf-8"> <title> Demo6: benutzerdefinierte altboard </title> </head> <body> <canvas id = "canvas"> Der Browser unterstützt keine Canvas <!-Wenn dieser Text nicht unterstützt wird, wird es angezeigt. onclick = 'linecolor = "gelb";'> gelb </button> <button onclick = 'linecolor = "rot";'> rot </button> <button onclick = 'linecolor = "blau";'> blau </button> <button onclick = 'linecolor = "green"; onclick = 'linecolor = "schwarz";'> schwarz </button> <br/> <button onclick = "linw = 4;"> 4px </button> <button onclick = "linw = 8;"> 8px </button> <button onclick = "linw = 16; <br/> <img src = "" id = "image_png"> <br/> <script type = "text/javascript"> var canvas = document.getElementById ('canvas'); // Holen Sie sich den Tag var ctx = canvas.getContext ("2D"); var fillstyle = "schwarz"; CTX.FillRect (0,0,600.300); var onoff = false; // Drücken Sie das Tag var oldx = -10; var oldy = -10; // Setzen Sie die Farb -var linecolor = "White"; var linw = 4; canvas.addeventListener ("Mousemove", zeichnen, wahr); // Mausbewegungsereignis Canvas.AdDeDeDListener ("MouseDown", Down, False); // Mouse Press Event canvas.adDeVentListener ("Mausup", up, false); // Maus-Popup-Ereignisfunktion Down (Ereignis) {Onoff = true; oldx = event.pagex - 10; oldy = event.pagey - 10; } function up () {onoff = false; } Funktion zeichnen (Ereignis) {if (onoff == true) {var newx = event.pagex - 10; var newy = event.pagey - 10 ctx.beginPath (); ctx.moveto (Oldx, Oldy); ctx.lineto (Newx, Newy); ctx.strokestyle = linecolor; ctx.linewidth = linw; ctx.linecap = "rund"; ctx.stroke (); oldx = newx; oldy = newy; }} function mopedimage (Ereignis) {var img_png_src = canvas.todataurl ("Image/png"); // Funktionen, die das altafel als Bildformat dokument speichern. } </script> </body> </html>Das Obige dreht sich alles um diesen Artikel, ich hoffe, es wird für das Lernen aller hilfreich sein.