canvas的drawImage()方法,图片不显示。
js代码:varxx=Math.ceil(Math.random()*8);varres=["images/hongluan.jpg","images/hongyan.j...
js代码:
var xx = Math.ceil(Math.random()*8);
var res = ["images/hongluan.jpg",
"images/hongyan.jpg",
"images/qiangnei.jpg",
"images/qiangwai.jpg",
"images/tianxi.jpg",
"images/xianchi.jpg",
"images/yumen.jpg",
"images/zhengyuan.jpg",
"images/muyu.jpg"];
var img = document.getElementById("img");
img.setAttribute("src",res[xx].toString());
var canvas = document.getElementById("thecanvas");
var cxt = canvas.getContext("2d");
cxt.drawImage(img,0,0,350,427);
html代码:
<img id="img" src="" alt="" style="display:none">
<canvas style="position: absolute; z-index: 1;bottom: 2%;" width=350 height=427 id="thecanvas"> 展开
var xx = Math.ceil(Math.random()*8);
var res = ["images/hongluan.jpg",
"images/hongyan.jpg",
"images/qiangnei.jpg",
"images/qiangwai.jpg",
"images/tianxi.jpg",
"images/xianchi.jpg",
"images/yumen.jpg",
"images/zhengyuan.jpg",
"images/muyu.jpg"];
var img = document.getElementById("img");
img.setAttribute("src",res[xx].toString());
var canvas = document.getElementById("thecanvas");
var cxt = canvas.getContext("2d");
cxt.drawImage(img,0,0,350,427);
html代码:
<img id="img" src="" alt="" style="display:none">
<canvas style="position: absolute; z-index: 1;bottom: 2%;" width=350 height=427 id="thecanvas"> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询