要引入图片可以用
<img id="scc" src="img_the_scream.jpg" width="320" height="220">
var img=document.getElementById("scc")
希望对你有帮助,望采纳!
今天心情好,给你补充完整吧。添加一个变量判断是否在画。。你对比一下我们的代码,你就知道什么意思了。。。。直接拷贝运行吧。如果还不成功,就换台电脑吧 哈哈。<!DOCTYPE HTML>
<!--This text is a comment-->
<html>
<head></head>
<script type="text/javascript">
var c = document.getElementById("myCanvas")
var drawtext=c.getContext("2d")
var startdraw = false
function begin(e)
{
var c = document.getElementById("myCanvas")
var drawtext=c.getContext("2d")
x=e.clientX
y=e.clientY
document.getElementById("xycoordinates").innerHTML="Coordinates: (" + x + "," + y + ")"
drawtext.beginPath()
drawtext.moveTo(x,y)
startdraw = true
}
function end(a)
{
if(startdraw)
{
var c = document.getElementById("myCanvas")
var drawtext=c.getContext("2d")
x1=a.clientX
y1=a.clientY
document.getElementById("xycoordinates").innerHTML="Coordinates: (" + x1 + "," + y1 + ")"
drawtext.lineTo(x1,y1)
drawtext.stroke()
}
}
function finish()
{
startdraw = false
}
</script>
<body>
<canvas id="myCanvas" height="700" width="1580" style="border:2px solid #06c"
onmousedown="begin(event)" onmousemove="end(event)" onmouseup="finish()"></canvas>
<div id="xycoordinates"></div>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)