Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
note-library
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
49e6c273
authored
May 12, 2020
by
肖康
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
x
parent
fd95f0c2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 additions
and
12 deletions
resources/views/web/showPage.blade.php
resources/views/web/showPage.blade.php
View file @
49e6c273
...
@@ -2,30 +2,19 @@
...
@@ -2,30 +2,19 @@
<
br
/>
<
br
/>
<
div
style
=
"border-top:1px solid #ccc;margin-top:20px;margin-bottom:20px;"
></
div
>
<
div
style
=
"border-top:1px solid #ccc;margin-top:20px;margin-bottom:20px;"
></
div
>
<
a
class
="
downpng
layui
-
btn
" target="
_blank
" href="" download="
downImg
">
下载
</a>
<
a
class
="
downpng
layui
-
btn
" target="
_blank
" href="" download="
downImg
">
下载<
/a>
<script src="
https
://
cdn
.
bootcdn
.
net
/
ajax
/
libs
/
html2canvas
/
0.5
.
0
-
beta4
/
html2canvas
.
js
"></script>
<script src="
https
://
cdn
.
bootcdn
.
net
/
ajax
/
libs
/
html2canvas
/
0.5
.
0
-
beta4
/
html2canvas
.
js
"></script>
<script>
<script>
//创建一个新的canvas
var canvas2 = document.createElement("
canvas
");
var canvas2 = document.createElement("
canvas
");
var _canvas = document.querySelector('.edit-con');
var _canvas = document.querySelector('.edit-con');
var w = parseInt(window.getComputedStyle(_canvas).width);
var w = parseInt(window.getComputedStyle(_canvas).width);
var h = parseInt(window.getComputedStyle(_canvas).height);
var h = parseInt(window.getComputedStyle(_canvas).height);
//将canvas画布放大若干倍,然后盛放在较小的容器内,就显得不模糊了
canvas2.width = w+Number($("
.
edit
-
con
").css("
borderWidth
").split("
px
")[0])*2;
canvas2.width = w+Number($("
.
edit
-
con
").css("
borderWidth
").split("
px
")[0])*2;
canvas2.height = h+Number($("
.
edit
-
con
").css("
borderWidth
").split("
px
")[0])*2;
canvas2.height = h+Number($("
.
edit
-
con
").css("
borderWidth
").split("
px
")[0])*2;
// canvas2.style.width = w + "
px
";
// canvas2.style.height = h + "
px
";
//可以按照自己的需求,对context的参数修改,translate指的是偏移量
var context = canvas2.getContext("
2
d
");
var context = canvas2.getContext("
2
d
");
context.translate(-$("
.
edit
-
con
").offset().left,-$("
.
edit
-
con
").offset().top);
context.translate(-$("
.
edit
-
con
").offset().left,-$("
.
edit
-
con
").offset().top);
// var context = canvas2.getContext("
2
d
");
// context.scale(2, 2);
html2canvas(document.querySelector('.edit-con'), { canvas: canvas2 }).then(function(canvas) {
html2canvas(document.querySelector('.edit-con'), { canvas: canvas2 }).then(function(canvas) {
//document.body.appendChild(canvas);
//canvas转换成url,然后利用a标签的download属性,直接下载,绕过上传服务器再下载
document.querySelector("
.
downpng
").setAttribute('href', canvas.toDataURL());
document.querySelector("
.
downpng
").setAttribute('href', canvas.toDataURL());
});
});
</script>
</script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment