该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//将dom树转换为canvas
function print_body() {
var test = $('div.helloworld');
html2canvas(test, {
onrendered : function(canvas) {
document.body.appendChild(canvas);
}
});
alert(test)
//然后调用下载的方法
download_canvas(test);
}
//将canvas画板导出
function download_canvas(oCanvas) {
var bMouseIsDown = false;
//var oCanvas = document.getElementById("thecanvas");
oCanvas.onmousedown = function(e) {
bMouseIsDown = true;
iLastX = e.clientX
- oCanvas.offsetLeft
+ (window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft);
iLastY = e.clientY
- oCanvas.offsetTop
+ (window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop);
}
oCanvas.onmouseup = function() {
bMouseIsDown = false;
iLastX = -1;
iLastY = -1;
}
oCanvas.onmousemove = function(e) {
if (bMouseIsDown) {
var iX = e.clientX
- oCanvas.offsetLeft
+ (window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft);
var iY = e.clientY
- oCanvas.offsetTop
+ (window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop);
iLastX = iX;
iLastY = iY;
}
}
function showDownloadText() {
document.getElementById("buttoncontainer").style.display = "none";
document.getElementById("textdownload").style.display = "block";
}
function hideDownloadText() {
document.getElementById("buttoncontainer").style.display = "block";
document.getElementById("textdownload").style.display = "none";
}
function convertCanvas(strType) {
if (strType == "JPEG") {
var oImg = Canvas2Image.saveAsJPEG(oCanvas, true);
}
if (!oImg) {
alert("Sorry, this browser is not capable of saving " + strType
+ " files!");
return false;
}
oImg.id = "canvasimage";
oImg.style.border = oCanvas.style.border;
oCanvas.parentNode.replaceChild(oImg, oCanvas);
showDownloadText();
}
saveCanvas(oCanvas, "JPEG");//在这里报错 说 无法找到 toDataURL 方法
function saveCanvas(pCanvas, strType) {
var bRes = false;
if (strType == "JPEG") {
bRes = Canvas2Image.saveAsJPEG(oCanvas);
}
if (!bRes) {
alert("Sorry, this browser is not capable of saving " + strType
+ " files!");
return false;
}
}
}