微信刷爆朋友圈活动页 截屏分享实现

<!DOCTYPE html>

<html lang="zh">

 

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<meta http-equiv="X-UA-Compatible" content="ie=edge" />

<title>屏幕截图 -- 微信专用</title>

</head>

 

<body>

<a type="button" id="down_button"><button id="creat">点击复制图片</button></a>

<div class="myImg" style="position:relative;">

<img src="body_background.png">

</div>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>

<script src="https://cdn.bootcss.com/html2canvas/0.5.0-beta4/html2canvas.js"></script>

<script type="text/javascript">

$("#creat").click(function() {

html2canvas($("body"), { // $(".myImg")是你要复制生成canvas的区域,可以自己选

onrendered: function(canvas) {

dataURL = canvas.toDataURL("image/png");

$("body").append(canvas);

console.log(dataURL);

//下载图片

$('#down_button').attr('href', dataURL);

$('#down_button').attr('download', 'body_background.png');

},

width: 320,

height: 400

})

})

</script>

</body>

 

</html>

 

 

引入cdn

posted @ 2018-08-08 16:25  博客小鹏鹏  阅读(287)  评论(0编辑  收藏  举报