javascript
html 桌面截图,如何使用javascript在html中截取屏幕截图?
您只能使用Canvas將圖像或視頻幀捕獲為屏幕截圖.但是如果要捕獲網頁上的特定元素,請嘗試以下庫:
html2canvas
這是代碼:
注意:在drawImage()函數中仔細調整尺寸
$(".drag").draggable();
$(".drag").droppable();
var takeScreenShot = function() {
html2canvas(document.getElementById("container"), {
onrendered: function (canvas) {
var tempcanvas=document.createElement('canvas');
tempcanvas.width=350;
tempcanvas.height=350;
var context=tempcanvas.getContext('2d');
context.drawImage(canvas,112,0,288,200,0,0,350,350);
var link=document.createElement("a");
link.href=tempcanvas.toDataURL('image/jpg'); //function blocks CORS
link.download = 'screenshot.jpg';
link.click();
}
});
}
#container{
width:400px;
height:200px;
}
#rightcontainer{
width:300px;
height:200px;
background:gray;
color:#fff;
margin-left:110px;
padding:10px;
}
#leftmenu{
color:#fff;
background-color:green;
width:100px;
height:200px;
position:fixed;
left:0;
padding:10px;
}
button{
display:block;
height:20px;
margin-top:10px;
margin-bottom:10px;
}
.drag{
width:40px;
height:20px;
background-color:blue;
z-index:100000;
margin-top:10px;
}
Snapshot
Left Side
Drag----------->
&
Click Snapshot
Right Side
總結
以上是生活随笔為你收集整理的html 桌面截图,如何使用javascript在html中截取屏幕截图?的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: android模拟器 后退键,MainA
 - 下一篇: html修改按钮背景颜色,html鼠标悬