多个叠加,右键保存只保存一个
新人,正在尝试。我试图通过堆叠随机选择的图层在 html/javascript 中创建单个图像(请参见下面的代码)。但是,当我右键单击图像时,它仅保存顶层,而不保存所有图层。我该如何解决这个问题(如果不使用任何库,则可以使用按钮 - 屏幕截图也一样)?
非常感谢!
船长
//html
<div><div id="layers"></div>
<canvas id="canvas1"></canvas>
// script
//create and attach layer1 to body;
var img = document.createElement('img');
img.alt = "Layer1";
img.src = layer1_array[getRandomInt(0,3)];
img.setAttribute("id","myImg");
img.style.decoding = "async";
document.getElementById("layers").appendChild(img);
//create and attach layer1 to body;
var img = document.createElement('img');
img.alt = "Layer2";
img.src = layer2_array[getRandomInt(0,3)];
img.setAttribute("id","myImg");
img.style.decoding = "async";
document.getElementById("layers").appendChild(img);
Newbie here, experimenting. I'm trying to create in html/javascript a single image by stacking randomly selected layers (see code below). However, when I right-click the image it only saves the top layer, not all layers. How do I fix this (a button would be possible if it does not use any libraries -same goes for screenshots)?
Many thanks in advance!
Skipper
//html
<div><div id="layers"></div>
<canvas id="canvas1"></canvas>
// script
//create and attach layer1 to body;
var img = document.createElement('img');
img.alt = "Layer1";
img.src = layer1_array[getRandomInt(0,3)];
img.setAttribute("id","myImg");
img.style.decoding = "async";
document.getElementById("layers").appendChild(img);
//create and attach layer1 to body;
var img = document.createElement('img');
img.alt = "Layer2";
img.src = layer2_array[getRandomInt(0,3)];
img.setAttribute("id","myImg");
img.style.decoding = "async";
document.getElementById("layers").appendChild(img);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)