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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值