前端 点击按钮将页面转换为图片保存至本地(html2canvas)

前端 点击按钮将页面转换为图片保存至本地(html2canvas)

1.引入html2canvas

	
	$(document).on('click','.savebtn',function() {
         html2canvas(document.querySelector(".shopimg"),{
               useCORS:true
          }).then(function (canvas) {
               let imgData = canvas.toDataURL('img/png');
               let aEle = document.createElement('a');
               aEle.href =imgData;
               aEle.download = 'img';
               aEle.click();
          })
    })

你可能感兴趣的:(前端)