2015-10-05 100 views
0

我从小提琴中获得了一个代码(http://jsfiddle.net/8ypxW/3/),用于将div转换为图像。 但是当我试图在我的网页它不工作.. 下面是我的代码....将div保存到图像(不工作)

plz帮助我的朋友实现.......

<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 

<script> 
$(function() { 
    $("#btnSave").click(function() { 
     html2canvas($("#widget"), { 
      onrendered: function (canvas) { 
       theCanvas = canvas; 
       document.body.appendChild(canvas); 

       // Convert and download as image 
       Canvas2Image.saveAsPNG(canvas); 
       $("#img-out").append(canvas); 
      } 
     }); 
    }); 
}); 
</script> 
</head> 
<body> 
<span id="widget" class="widget"> 
    this is text. 
</span> 
<br/> 
<button id="btnSave">Save PNG</button> 

<div id="img-out"></div> 


</body> 

</html> 

回答

1

你只有jQuery核心包括在内。您需要项目中包含的其他js文件。

<script type='text/javascript' src="https://github.com/niklasvh/html2canvas/releases/download/0.4.1/html2canvas.js"></script> 

    <script type='text/javascript' src="http://www.nihilogic.dk/labs/canvas2image/base64.js"></script> 

    <script type='text/javascript' src="http://www.nihilogic.dk/labs/canvas2image/canvas2image.js"></script> 
+0

由于现在它的工作....但在小提琴..他们力包括任何文件....所以我认为这将无需增加额外的文件 –

+0

的小提琴也包括他们的工作。在左边查找'外部资源',这将列出任何外部资源与CSS文件或js文件。 –

+0

ohhhh非常感谢.... :) –

0

你参考正确的库?在你的代码中,你只能加载jquery文件。