但是我没有在浏览器中看到任何结果,默认情况下为“img src”。请有人帮助我。我该如何使用这个功能?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<canvas width="500" height="250"></canvas>
</head>
<script src="jquery.js"></script>
<script src="jcanvas.js"></script>
<script>
$("canvas").drawImage({
source: $('#draggable')[0],
x: 50, y: 50,
width: 60,
fromCenter: false
});
</script>
<body>
<img src="../image/0.jpg" class="drag-image" id="draggable"/>
</div>
</body>
</html>
感谢。
答案 0 :(得分:2)
图像标记未完全加载。结果,$('#draggable')[0]返回undefined。尝试在加载文档时调用drawImage。 以下内容应该可以解决您的问题。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<canvas width="500" height="250"></canvas>
</head>
<script src="jquery.js"></script>
<script src="jcanvas.js"></script>
<script>
$(document).ready(function(){
$("canvas").drawImage({
source: $('#draggable')[0],
x: 50, y: 50,
width: 60,
fromCenter: false
});
});
</script>
<body>
<img src="../image/0.jpg" class="drag-image" id="draggable"/>
</div>
</body>
</html>