问答详情
源自:2-4 Canvas基础 使用滑杆交互

不知错哪了

var canvas = document.getElementById('canvas');

var context = canvas.getCotext('2d');

var slider = document.getElementById('scale-range');

var image = new Image();


window.onload = function(){

canvas.width = 1920;

canvas.height = 1080;


var scale = slider.value;

image.src = "banner.jpg";

image.onload = function(){

drawImageByScale(scale);

slider.onmousemove = function(){

scale = slider.value;

drawImageByScale(scale);

}

}

}

function drawImageByScale(scale){

var imageWidth = 1920 * scale;

var imageHeight = 1080 * scale;

var dx = canvas.width/2 - imageWidth/2;

var dy = canvas.height/2 - imageHeight/2;

context.clearRect(0,0,canvas.width,canvas.height);

context.drawImage(image,dx,dy,imageWidth,imageHeight);

}


提问者:宝慕林2917688 2016-12-30 16:09

个回答

  • YnezWood
    2017-05-19 10:54:54

    所以提示的错误是什么

  • LXJ24
    2016-12-30 17:39:22

    代码没问题