html 塗鴉功能,及傳資料到後台

來源:互聯網
上載者:User

標籤:

var c=document.getElementById("myCanvas");var cxt=c.getContext("2d");cxt.lineWidth=5;cxt.strokeStyle="#000000";cxt.lock=false;$("#myCanvas").mousedown(function(e) {cxt.beginPath();//清空子路徑cxt.lock=true;var mousePos = getMousePos(c, e);cxt.moveTo(mousePos.x,mousePos.y);this.setCapture && this.setCapture();return false;// document.getElementById("xycoordinates").innerHTML="Coordinates: (" + x + "," + y + ")";});document.onmousemove = function(e) {if(cxt.lock){var mousePos = getMousePos(c, e);var x=mousePos.x;var y=mousePos.y;cxt.lineTo(x,y);cxt.stroke();return false;}}$("body").mouseup(function(e) {cxt.lock=false;cxt.closePath() ;//閉合路徑return true;// document.getElementById("xycoordinates").innerHTML="Coordinates: (" + x + "," + y + ")";});$("#submitimage").click(function(){$("#imageurl").val(c.toDataURL());});//canvas滑鼠定位function getMousePos(canvas, evt) {var rect = canvas.getBoundingClientRect();return {x: evt.clientX - rect.left * (canvas.width / rect.width),y: evt.clientY - rect.top * (canvas.height / rect.height)}}//顏色賦值var color = new Array("#000000","#0066FF","#6600FF","#993366","#33CC66","#FF3300");for(var i=0; $("#selectcolor li").eq(i).val()==0;i++){$("#selectcolor li").eq(i).css("background-color",color[i]);}//顏色選取$("#selectcolor li").click(function(){cxt.strokeStyle=$(this).css("backgroundColor");});//畫筆大小$("#pensize li").click(function(){if($(this).text()=="細"){cxt.lineWidth=5;}else if($(this).text()=="中"){cxt.lineWidth=10;}else{cxt.lineWidth=15;}});$("#canvasreset").click(function(){cxt.clearRect(0, 0, c.width, c.height);//清除畫布,左上方為起點});

  

html 塗鴉功能,及傳資料到後台

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.