简体   繁体   English

如何在没有源的情况下获取透明元素的图像?

[英]How to get the image of a transparent element without source?

I see an element in a HTML5 game which can be rotated, hidden and moved.我在 HTML5 游戏中看到一个可以旋转、隐藏和移动的元素。 But it has a background... And the element is transparent.但它有一个背景……而且元素是透明的。

For example, this moves the element:例如,这将移动元素:

$("#elementr2").animate({left: '650px'});

I can capture it perfectly because it is transparent.我可以完美地捕捉它,因为它是透明的。

What could I do?我能做什么?

Do you mean that you want to download the image asset?您的意思是要下载图像资产吗? You could check the network tab and find the resource there.您可以检查网络选项卡并在那里找到资源。 It will probably be on its own or in a sprite sheet.它可能单独存在或在精灵表中。 Just filter the list by .png then right click on the asset, open in new window, right click, save as.只需按 .png 过滤列表,然后右键单击资产,在新窗口中打开,右键单击,另存为。

Okay... If you can do this:好的...如果你能做到这一点:

$("#elementr2").animate({left: '650px'});

Then, you can set a perfect white background covering the whole screen and bring only the wanted element above it.然后,您可以设置覆盖整个屏幕的完美白色背景,并仅将所需元素置于其上方。

// This will set a white background.
var myBackground = $("<div>").attr("style","width:100%;"+
                                   "height:100%;"+
                                   "top:0;"+
                                   "right:0;"+
                                   "bottom:0;"+
                                   "left:0;"+
                                   "background-color:#FFF;"+
                                   "position:fixed;"+
                                   "z-index:999999;"
                                  );

// This will bring the element you want above the background.
$("body").append(myBackground);
$("#elementr2").css({"position":"fixed",
                     "z-index":"1000000",
                    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM