点击截图功能 js canvas

使用:html2canvas实现浏览器截图

<html>
<head>
<meta name="layout" content="main">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://html2canvas.hertzen.com/build/html2canvas.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".example1").on("click", function(event) {
event.preventDefault();
html2canvas($(".aa"), {
// height: $(".aa").outerHeight() + 20,
allowTaint: true,
taintTest: false,
onrendered: function(canvas) {
canvas.id = "mycanvas";
//document.body.appendChild(canvas);
//生成base64图片数据
var dataUrl = canvas.toDataURL();
var newImg = document.createElement("img");
newImg.src = dataUrl;
newImg.className = 'img'
$(".product").before(newImg);
}
});
});
});
</script>
</head>
<body>
Hello!
<div class="aa" style="background-color: #abc;">
test test test test test test
</div>
<textArea id="textArea" col="20" rows="10"></textArea>
生成界面如下:
<div class="product">
<input class="example1" type="button" value="button">
</div>
</body>
</html>

参考:http://www.cnblogs.com/yanweidie/p/5203943.html#_label0

上一篇:SOFA 源码分析— 事件总线


下一篇:Centos环境下部署游戏服务器-常用命令