[英]how to show lightbox popup with image?
在下面的代码中。 单击保存按钮后,它要求下载从Html2canvas生成的输出图像。 如何修改此代码,以便即时询问是否要下载它,并将使用“灯箱”功能即时生成图像。
我尝试为:
<html>
<head>
<meta charset="utf-8"/>
<title>test2</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"></script>
<script type="text/javascript" src ="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="html2canvas.js?rev032"></script>
<script type="text/javascript">
$(window).load(function() {
$('#load').click(function() {
html2canvas($('#testdiv'), {
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
window.location.href = img;
}
});
});
});
</script>
</head>
<body>
<div id="testdiv">
<h1>Testing</h1>
<h4>One column:</h4>
<table border="1">
<tr>
<td>100</td>
</tr>
</table>
<br/>
</div>
<input type="button" value="Save" id="load"/>
</body>
</html>
你可以试试
$("#containerID").empty().append(canvas); // containerID is the container element for your rendered image
在页面上添加图片。 并以相同的方式尝试将canvas或img(视情况而定)作为URL传递给灯箱代码。
而不是像在这里那样将访问者重定向到图像:
window.location.href = img;
您可以在页面上添加不可见的( display: none
)图像:
<img src="" id="image" style="display: none; position: absolute; top: 30%; left: 30%; z-index: 1000;" />
并用您的画布图像数据显示它,如下所示:
$('#image').attr('src', img).fadeIn(200);
现在,如果不做一些额外的工作,就不会创建一个非常有趣的灯箱,但是为此,我建议您使用一个插件。 Slimbox或Fancybox之类的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.