console
var getPixelRatio = function(context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
console.log('backingStore', backingStore, window.devicePixelRatio);
return (window.devicePixelRatio || 1) / backingStore;
};
function initCanvas(tpl, selector, callback) {
var img;
var canvas;
var ctx;
var ratio;
canvas = tpl.find(selector)[0];
ctx = canvas.getContext('2d');
ratio = getPixelRatio(ctx);
img = new Image();
img.width = canvas.width / ratio;
img.height = canvas.height / ratio;
console.log('ratio', ratio)
console.log(canvas.width)
img.addEventListener('load', function() {
ctx.drawImage && ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#fc5f16';
ctx.font = '15px serif';
ctx.textAlign = 'center';
ctx.fillText('刮开有惊喜 免费送大礼', canvas.width / (2 * ratio), 25);
ctx.globalCompositeOperation = 'destination-out';
startFun = startFun.bind(null, canvas);
moveFunc = moveFunc.bind(null, canvas, ctx, ratio);
endFunc = endFunc.bind(null, canvas, ctx);
canvas.addEventListener('touchstart', startFun, false);
canvas.addEventListener('touchmove', moveFunc, false);
canvas.addEventListener('touchend', endFunc, false);
callback();
});
console.log(png);
img.src = png;
}
<canvas id="scratchcard-cvs" width="202" height="96"></canvas>