js使用html2canvas 生成图片然后下载
首先去官网把这个JS下载下来
<!DOCTYPE html>
<html lang="en">
<head>
<title> </title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="{:__STYLE__}css/x-admin.css" media="all">
</head>
<style type="text/css">
.contanie{
/*background: pink;*/
font-size: 16px;
width: %;
}
.contanie .fonter_code{
position: fixed;
bottom: ;
right: ;
background: red;
display: block;
background: #fff;
width: %; }
.fonter_code button{
float: right;
}
.code_title{
min-height: 90px;
background: #ff9f0f5e;
font-size: 40px;
width: %;
text-align: center;
font-weight: ;
font-family: monospace; }
.code_title_footer{
min-height: 90px;
background: #fff;
font-size: 20px;
width: %;
text-align: center;
display: inline-block; }
.code_conter_qr{
min-height: 400px;
background: #fff;
text-align: center;
/*padding: 0 30px; */
margin: 50px;
border-bottom: 1px solid #ffd9229c;
}
.code_conter_qr img {
width: 250px;
height: 250px;
display: block;
margin: auto;
border: 1px solid #ffd9229c ;
border-radius: 6px;
}
.code_span_title{
font-weight: bold ;
font-size: 65px;
display: block;
padding: 20px ; }
.code_title_footer .code_qr_code span{
font-size: 16px;
font-weight: bold; }
.code_qr_code img{
width: 40px;
display: inline-block;
padding: 5px;
}
.code_qr_code{
line-height: 90px;
}
</style>
<body>
<div class="contanie">
<div class="contet_code" id="upload_code">
<div class="code_title">
<span style="line-height: 90px;">
{$data['bname']} 收钱码
</span>
</div>
<div class="code_conter_qr">
<div class="code_span_title">
<span>在此扫码付款</span>
</div>
<img src="{:__UPLOAD__}{$data['img']}">
</div>
<div class="code_title_footer ">
<div class="code_qr_code">
<span>支持付款方式:</span>
<img src="{:__UPLOAD__}imgs/zfb.png">
<img src="{:__UPLOAD__}imgs/wx.png">
</div> </div>
</div>
<div class="fonter_code">
<button type="button" class="layui-btn layui-btn-normal" onclick="onsubmint()"> 下载</button>
</div>
</div>
<script src="{:__STYLE__}lib/layui/layui.js" charset="utf-8"></script>
<script src="{:__STYLE__}js/x-layui.js" charset="utf-8"></script>
<script src="{:__STYLE__}js/jquery.min.js" charset="utf-8"></script>
<script src="{:__STYLE__}js/html2canvas.js" charset="utf-8"></script>
<script type="text/javascript"> function onsubmint(){
html2canvas(document.querySelector("#upload_code")).then(canvas => {
var pageData = canvas.toDataURL('image/jpeg', 1.0);
saveFile(pageData.replace("image/jpeg", "image/octet-stream"),new Date().getTime()+".jpeg"); });
var saveFile = function (data, filename) {
console.log(data);
var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
save_link.href = data;
save_link.download = filename;
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, false, window, , , , , , false, false, false, false, , null);
save_link.dispatchEvent(event);
}; } </script> </body>
</html>
效果图

js使用html2canvas 生成图片然后下载的更多相关文章
- 通过JS将BSAE64生成图片并下载
HTML:<div style="display:block;margin:0 auto;width:638px;height:795px;"><div id=& ...
- html2canvas 网页截图 下载 上传
利用html2canvas插件 对网页截图 并下载和上传图片. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//E ...
- 前端js保存页面为图片下载到本地
前端js保存页面为图片下载到本地 手机端点击下载按钮将页面保存成图片到本地 前端js保存页面为图片下载到本地的坑 html2canvas 识别 svg 解决方案 方案 html2canvas.js:可 ...
- JS - 使用 html2canvas 将页面转PDF
JS - 使用 html2canvas 将页面转PDF 本方法可以将页面元素块转为pdf. 网站地址 jspdf.js 官网地址:http://jspdf.com GitHub 主页:https:// ...
- js、css引用文件的下载方式
js.css引用文件的下载方式 一.测试(chrome):1.直接使用<script...>.<link...>标签来混合引入脚本文件和css文件, <script as ...
- js中使用showModelDialog中下载文件的时候,闪一下后无法下载
在js中使用showModelDialog中下载文件的时候,会因为showModelDialog自动设置target为_self导致下载文件“只会闪一下”就消失掉 在吧target设置为_blank后 ...
- js接收文件流并下载
js接收文件流并下载 标签(空格分隔): js 在此输入正文 <script type="text/javascript"> function download(fil ...
- 移动端js模拟截屏生成图片并下载功能的实现方案
一.根据PM需求如下: 移动端wap 实现将二维码生成图片下载至用户手机相册保存 二.根据现有思路: 1.使用第三方工具html2canvas,将页面中指定范围的dom转换为canvas 2.随后使用 ...
- 使用html2canvas.js将HTML生成图片
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- 感知机算法(PLA)代码实现
目录 1. 引言 2. 载入库和数据处理 3. 感知机的原始形式 4. 感知机的对偶形式 5. 多分类情况-one vs. rest 6. 多分类情况-one vs. one 7. sklearn实现 ...
- python爬虫入门(1)----- requests
介绍 requests是python实现的简单易用的HTTP库,使用起来比urllib简洁很多 基本使用 requests.get("http://www.baidu.com") ...
- node学习第一天
创建服务器 利用require引入http模块:var http=require("http") 利用http模块创建server服务器; 创建服务器:var server=htt ...
- vue+springboot文件上传
//vue element-ui组件 <el-upload style="position: relative;top: -40px;left: 240px;" ...
- vue学习(四) v-on:事件绑定
//html <div id="app"> <input type="button" value="ok" v-bind: ...
- Eclipse创建Web项目后新建Servlet时报红叉错误 or 导入别人Web项目时报红叉错误 的解决办法
如图,出现类似红叉错误. 1.在项目名称上点击右键->Build Path->Configure Build Path 2.在弹出来的框中点击Add Library,如图 3.接下来选择U ...
- yum下载软件包
方法一: downloadonly插件有一个yum的插件叫做downloadonly,就是只下载不安装的意思.1. 安装插件yum install yum-download2. 下载yum updat ...
- python处理excel文件(xls和xlsx)
一.xlrd和xlwt 使用之前需要先安装,windows上如果直接在cmd中运行python则需要先执行pip3 install xlrd和pip3 install xlwt,如果使用pycharm ...
- 网络通信协议、UDP通信、TCP通信
网络通信协议 网络通信协议有很多种,目前应用最广泛的是TCP/IP协议,它是一个包括TCP协议和IP协议,UDP协议和其它一些协议的协议组. IP地址和端口号 目前,IP地址广泛使用的版本是IPv4, ...
- 2019 HL SC day1
今天讲的是图论大体上分为:有向图的强连通分量,有向图的完全图:竞赛图,无向图的的割点,割边,点双联通分量,变双联通分量以及圆方树 2-sat问题 支配树等等. 大体上都知道是些什么东西 但是仍需要写一 ...