标签:download dom can var htm trigger 渲染 color display
/** * 下载图片 * <a id="download-IMG" style="display:none;"><span>下载</span></a> */ /* 使用html5默认的下载功能,下载图片 */ function downloadImgByHtml5() { var imgName = "图片名"; var imgSrc = "../images/normal.png"; $(‘#download-IMG‘).attr(‘href‘, imgSrc).attr(‘download‘, imgName); $(‘#download-IMG‘).children("span").trigger("click"); } /** * 使用html2canvas下载图片 * 适用范围:不支持html5的下载或者无效时,且图片在页面中显示; * 原理:使用html2canvas插件,将页面中的DOM元素渲染成图片; */ function downloadImgByHtml2canvas() { var imgName = "图片名"; html2canvas($(‘#fancybox-img‘), { onrendered: function(canvas) { var base64Img = canvas.toDataURL("image/png"); $(‘#download-IMG‘).attr(‘href‘, base64Img).attr(‘download‘, imgName); $(‘#download-IMG‘).children("span").trigger("click"); } }); }
标签:download dom can var htm trigger 渲染 color display
原文地址:http://www.cnblogs.com/huliang56/p/6148260.html