简体   繁体   English

使用jQuery / JavaScript划分图像

[英]Div to image with jQuery/JavaScript

I am trying to convert div to image using html2canvas library. 我正在尝试使用html2canvas库将div转换为图像。 I tried but no success can't convert full div to image, the dropper is missing in image. 我尝试但没有成功无法将完整的div转换为图像,图像中缺少滴管。

URL : https://www.makethatvape.com/ejuicecalc/ 网址https//www.makethatvape.com/ejuicecalc/

Tried with code: 试过代码:

html2canvas($("#widget")).then(function(canvas) {
   bimg = canvas.toDataURL();  // by default png
});

So, any idea how to overcome this problem. 所以,任何想法如何克服这个问题。 I played with html2canvas and it work for text and CSS div to canvas conversion. 我玩html2canvas,它适用于文本和CSS div到画布转换。

Try this 试试这个

<div id="copyDiv"></div>

    var element = $("#widget"); // global variable
    var getCanvas; // global variable

    html2canvas(element, {
             onrendered: function (canvas) {
                    $("#copyDiv").append(canvas);
                    getCanvas = canvas;
                 }
      });

Detail Article: Convert Div to Image in jQuery 详细文章: 在jQuery中将Div转换为图像

Simpler way to do it: 更简单的方法:

var convertMeToImg = $('#myDiv')[0];

html2canvas(convertMeToImg).then(function(canvas) {
    $('#resultsDiv').append(canvas);
});

https://html2canvas.hertzen.com/getting-started https://html2canvas.hertzen.com/getting-started

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM