【发布时间】:2015-02-01 18:13:55
【问题描述】:
所以我有一个 3D 游戏,它带有一个 three.js 透视相机,它在 3D 空间中移动。现在,当您在此 3D 空间中“选择”了一个项目时,我希望在屏幕左上角出现一个按钮来取消选择该项目。有没有办法使用 html 来做到这一点?因为现在我有一个按钮,但它正在将游戏推到它下面,而不是作为它的一部分,这是 html 所期望的。我想我需要使按钮的背景透明并手动将游戏推到屏幕顶部。
<body style="background-color: #222222;">
//Here is the button that I need to be transparent
//because I have no way to test it, I have no idea if that style code I have makes it transparent or not
<input type="image" id="myimage" style="height:200px;width:200px;border:0 none;background-color: transparent;" src="media/undo.png"/>
<script src="src/game.js"></script>
<script src="src/main.js"></script>
//Here is where I load in the game
<script>
$(document).ready(function(){
//All loading stuff
THREE.ImageUtils.crossOrigin = '';
var game = new Main($(document).width() - 10, $(document).height() - 20, "res/games.json");
game.init();
function gameUpdate(){
game.update();
window.requestAnimationFrame(gameUpdate, game.renderer.domElement);
}
gameUpdate();
});
</script>
//Done with game loading script
</body>
这是问题的图片:http://puu.sh/dg4rJ/5a25c817b7.jpg 我需要游戏和按钮在一起。有没有办法做到这一点,还是我应该在 JS 的游戏中努力做到这一点?
【问题讨论】:
-
你试过添加 position:absolute 吗?
-
如有必要,更改 CSS 中的
z-index。图片的背景应该是透明的。
标签: javascript html css image button