为了账号安全,请及时绑定邮箱和手机立即绑定

下面代码哪里错了,为什么画布中就是不显示图片

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style>

*{margin: 0; padding: 0;}

a{text-decoration: none; font-family: "microsoft yahei"}

.blur-img{position: relative; width: 1440px; height: 900px; margin: 0 auto;}

.blur-img img{width: 1440px; height: 900px; filter: blur(20px);-webkit-filter: blur(20px); -moz-filter:blur(20px); -o-filter:blur(20px); -ms-filter:blur(20px); z-index: 1;}

#canvas{position: absolute; left: 0; top: 0; z-index: 100; display: block;}

.blur-btn{position: absolute; bottom: 0; width: 80px; height: 30px; text-align: center; line-height: 30px; font-size: 16px; color: #fff; background: #218868; display: block; z-index: 102;}

.blur-btn.reset{left: 200px;}

.blur-btn.show{right: 200px; background: #CD69C9;}

</style>

</head>

<body>

<div>

<img src="images/1.jpg" alt="">

<canvas id="canvas">

该浏览器不支持canvas,请更换

</canvas>

<a href="##" class="blur-btn reset">RESET</a>

<a href="##" class="blur-btn show" >SHOW</a>

</div>

<script>

var canvasWidth = 1440;

var canvasHeight = 900;

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

var context = canvas.getContext("2d");


canvas.width = canvasWidth;

canvas.height = canvasHeight;


var image = new Image();

image.src = "1.jpg";

image.onload = function(e){

context.drawImage(image,0,0);

}

</script>

</body>

</html>


正在回答

1 回答

image.src = "1.jpg";

上面这段代码少了文件夹名称。

image.src = "images/1.jpg";

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

下面代码哪里错了,为什么画布中就是不显示图片

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信