body {
margin: 0;
padding: 0;
background: #fff;
}
/* , */
.tb {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 40px;
overflow: hidden;
border-bottom: 1px solid #CCC;
background-color: orange;
}
canvas {
position: absolute;
top: 40px;
left: 0;
}
/* */
.bt {
overflow: hidden;
float: left;
font-weight: bold;
color: white;
font: 16px Arial;
width: 33%;
padding-top: 10px;
height: 30px;
text-align: center;
}
/* select */
select {
float: left;
width: 33%;
margin-top: 10px;
height: 20px;
}
... <head> <meta name="viewport" content="width=device-width,user-scalable=no" /> </head> ...
<!-- , --> <div id="tb" style="z-index: 2"> <div class="bt"></div> <div class="bt"></div> <a class="bt"></a> </div> <!-- , --> <div id="htb" style="opacity: 0; z-index: 3"> <select id="hcs"> <option>blue</option> <option>red</option> <option>green</option> <!-- --> </select> <select id="hss"> <option>10</option> <option>11</option> <option>12</option> <!-- --> </select> <a class="bt" id="savebutton" style="z-index: 20;"></a> </div>
someElement.ontouchstart = function(e) { console.log("X: " + e.touches[0].pageX + ", Y:" + e.touches[0].pageY); }
var width = window.innerWidth; // var height = window.innerHeight; // var hcanv = document.createElement("canvas"); // var mcanv = document.createElement("canvas"); // // mcanv.width = width; mcanv.height = height; hcanv.width = width; hcanv.height = height; // DOM document.body.appendChild(mcanv); document.body.appendChild(hcanv); hcanv.style.zIndex = 10; // // var mctx = mcanv.getContext("2d"); var hctx = hcanv.getContext("2d");
var selects = document.getElementsByTagName("select"); // select for(var i=0; i<selects.length; i++) { // selects[i].onchange = handleSelects; // } function handleSelects() { // var val = this.options[this.selectedIndex].value; switch(this.id) { // , case "hcs": brush.color = val; // break; case "hss": brush.size = val; // break; } }
var touches = {x:[], y:[]}; // var brush = {color: "blue", size: 10}; // var snapshot = ""; // hcanv.ontouchstart = function(e) { // // touches.x.push(e.touches[0].pageX); touches.y.push(e.touches[0].pageY-40); //40 - hctx.clearRect(0, 0, width, height); // redraw(hctx); // () return false; // - } hcanv.ontouchmove = function(e) { // // touches.x.push(e.touches[0].pageX); touches.y.push(e.touches[0].pageY-40); hctx.clearRect(0, 0, width, height); // redraw(hctx); // () return false; // - ( etc) } hcanv.ontouchend = function(e) { // snapshot = hcanv.toDataURL(); // URL png var img = new Image(); // img.src = snapshot; // url img.onload = function() { // ( ) mctx.drawImage(img, 0, 0); // hctx.clearRect(0, 0, width, height); // } // touches.x = []; touches.y = []; } // function redraw(ctx) { ctx.lineCap = "round"; // ctx.lineJoin = "round"; // ctx.strokeStyle = brush.color; // ctx.lineWidth = brush.size; // ctx.beginPath(); if(touches.x.length < 2) { //, ctx.moveTo(touches.x[0], touches.y[0]); ctx.lineTo(touches.x[0] + 0.51, touches.y[0]); ctx.stroke(); ctx.closePath(); return; } ctx.moveTo(touches.x[0], touches.y[0]); ctx.lineTo((touches.x[0] + touches.x[1]) * 0.5, (touches.y[0] + touches.y[1]) * 0.5); var i = 0; while(++i < (touches.x.length -1)) { var abs1 = Math.abs(touches.x[i-1] - touches.x[i]) + Math.abs(touches.y[i-1] - touches.y[i]) + Math.abs(touches.x[i] - touches.x[i+1]) + Math.abs(touches.y[i] - touches.y[i+1]); var abs2 = Math.abs(touches.x[i-1] - touches.x[i+1]) + Math.abs(touches.y[i-1] - touches.y[i+1]); if(abs1 > 10 && abs2 > abs1 * 0.8) { //, ctx.quadraticCurveTo(touches.x[i], touches.y[i], (touches.x[i] + touches.x[i+1]) * 0.5, (touches.y[i] + touches.y[i+1]) * 0.5); continue; } ctx.lineTo(touches.x[i], touches.y[i]); ctx.lineTo((touches.x[i] + touches.x[i+1]) * 0.5, (touches.y[i] + touches.y[i+1]) * 0.5); } ctx.lineTo(touches.x[touches.x.length-1], touches.y[touches.y.length-1]); ctx.moveTo(touches.x[touches.x.length-1], touches.y[touches.y.length-1]); ctx.stroke(); ctx.closePath(); }
Source: https://habr.com/ru/post/126432/
All Articles