html2canvas无法截取div中的全部内容,非常急

兵工厂三剑客 2017-12-19 02:58:21
要截取的div如下:

<body>
<div class="M-weather sunny-bg" id="weather_id">
<div class="weather-head">
<h1>天气预报情况</h1>
<select name="city" id="city" onchange="changeCity(this)">
<option value="广州市">广州市</option>
<option value="深圳市">深圳市</option>
</select>
</div>
<!--<p class="weather-p">温馨提示:夜间有大雨,请带好雨具</p>-->
<ul class="weather-content" id="weatherSource">

</ul>

<script type="text/x-dot-template" id="weatherSourceTmpl">
{{~it:item}}
<li class="today">
<p>{{=item.dateDescribe}}</p>
<!--<span class="weather-icon"></span>-->
<span class="weather-icon">
<i class="{{=item.weatherTypePic}}"></i>
</span>
<p>{{=item.weatherTypeName}}<br>{{=item.minTemperature}}/{{=item.maxTemperature}}度</p>
<p>{{=item.windDiretion}} ≤{{=item.windLevel}}级</p>
</li>
{{~}}
</script>
</div>
</body>


截取的代码是这样写的:

var weather_canvas=null;
html2canvas($("#weather_id"),{
allowTaint: true,
taintTest: false,
onrendered: function(canvas) {
canvas.id = "mycanvas";
//document.body.appendChild(canvas);
//生成base64图片数据
weather_canvas = canvas.toDataURL();
//console.log(weather_canvas);
top.weatherpic=weather_canvas;
}
});

但是截取到的图像,图像中只有“天气预报清空”,城市这些东西。script标签中的内容没有。

请问该怎么解决,才能完整截取body中的内容。非常急。
...全文
924 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 1 楼 天际的海浪 的回复:
天气数据是用ajax加载的吧,你要等到ajax加载完,数据输出到页面上之后再用html2canvas截取
FarerLin 2019-03-20
  • 打赏
  • 举报
回复
楼主有没有遇见过要截的div比较长,屏幕显示不下的情况下,屏幕显示在div顶端,截图没问题,但是屏幕显示在div的底端的时候,截图就不全了,上部没显示的截不了。
兵工厂三剑客 2017-12-19
  • 打赏
  • 举报
回复
引用 1 楼 jslang 的回复:
天气数据是用ajax加载的吧,你要等到ajax加载完,数据输出到页面上之后再用html2canvas截取
是的,如你所说。我已经解决了。
天际的海浪 2017-12-19
  • 打赏
  • 举报
回复
天气数据是用ajax加载的吧,你要等到ajax加载完,数据输出到页面上之后再用html2canvas截取

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧