Javascript HTML2Canvas选项语法

Javascript HTML2Canvas选项语法,javascript,html2canvas,Javascript,Html2canvas,我在HTML2Canvas脚本的文档中苦苦挣扎。具体地说,这些选项位于。通过使用如下对象,我大致了解了语法:html2canvas(元素,{option:value})

我在HTML2Canvas脚本的文档中苦苦挣扎。具体地说,这些选项位于。通过使用如下对象,我大致了解了语法:
html2canvas(元素,{option:value})
我的具体目标是在我的站点上显示一个div,大约是1000px 500px,但保存的图像是这个大小的两倍。(我想保存一张1920 x 1080的图像,但我希望定制的div在构建时能舒适地显示在屏幕上。)

我猜我需要使用宽度、高度、比例、windowWidth和windowHeight选项的组合,但我只能算出宽度和高度的值语法。有谁熟悉这个脚本,可以为我指出正确的方向吗?

这里有一个例子,我在页面上抓取一个div的内容,然后将其呈现到画布上,如下所示:

var target_container = document.getElementById("id_of_div_I_want_to_render_on_canvas");
html2canvas(target_container, {
    onrendered: function(canvas) {
        var canvas_image = canvas.toDataURL("image/png"), // change output image type here
            img = new Image(); // create a new blank image

        img.src = canvas_image; // set the canvas_image as the new image's source
        img.width = el.offsetWidth; // make the image the same width and height as the target container
        img.height = el.offsetHeight;
        img.onload = function () {
            // do stuff
        });
    },
    width: <set your desired canvas width if you do not use my sizing above for img.width, img.height - e.g. '1000px'>,
    height: <set your height e.g. '500px'>
});
var target\u container=document.getElementById(“id\u of_div\u我希望\u在画布上渲染”);
html2canvas(目标容器{
onrendered:函数(画布){
var canvas_image=canvas.toDataURL(“image/png”),//在此处更改输出图像类型
img=new Image();//创建一个新的空白图像
img.src=canvas\u image;//将canvas\u图像设置为新图像的源
img.width=el.offsetWidth;//使图像的宽度和高度与目标容器相同
img.高度=标高离视线;
img.onload=函数(){
//做事
});
},
宽度:,
高度:
});

就我而言,关键属性是
onrendered
回调,它允许您在渲染后调用函数,并将“动态”生成的画布存储在图像中。

嗯,
window.devicePixelRatio
window.innerWidth
window.innerHeight
都是数字,所以我想试试数字。我试过了,但不幸的是我没有任何运气。我试过100,例如“100px”。不走运。宽度和高度采用直线数字,但它会将画布拉伸到新的尺寸,而div不会跟随。。。我刚刚有了一个主意,把我的div翻了一番,用百分比来衡量孩子们。我仍然想了解其他三个选项应该实现什么。