HTML2Canvas does not render full div, only what is visible on screen?

前端 未结 10 1858
甜味超标
甜味超标 2020-12-13 04:02

I\'m trying to use HTML2Canvas to render the contents of a div. Here is the code:

var htmlSource = $(\'#potenzial-page\')[0];

$(\'#btn\').on(\"click\", fun         


        
10条回答
  •  情书的邮戳
    2020-12-13 04:31

    If you have a height set to the div you want to turn to a canvas - you need to remove that before actually taking the snapshot. Otherwise it will just cut it off because of that height.

     $(".yourElemThatHasSomeHeightSet").css("height", "");
    

    Then you will notice that scrolling down - will still cut your document. Simply do a:

    $("html, body").scrollTop(0);
    

    before taking the snapshot.

提交回复
热议问题