如何在全屏html5游戏中居中放置广告

How to center an advertisement in a fullscreen html5 game?

本文关键字:中居 游戏 html5      更新时间:2023-09-26

如何在全屏html5游戏中居中放置广告?我的游戏设计成在玩的时候可以在你的浏览器上全屏显示。我希望我的广告总是在中心,无论它是否在平板电脑/个人电脑等上播放。

那么我该如何集中广告呢?

这是我的广告代码

<div id="goog" style="position:absolute; left:0; top:10;">
<script type="text/javascript">
<!--
google_ad_client = "ca-pub-xxxxxxxxx";
google_ad_slot = "xxxxxxxx";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div>

我试过这个document.getElementById("goog").align = 'center';,但它不起作用。

你可以试试这个

更改<div id="goog" style="position:absolute; left:0; top:10;">

<div id="goog" style="position:absolute; left:50%; top:50%;margin-top:-125px;margin-left:-175px;width:350px;height:250px;">

<style>
    #goog { position:absolute; left:50%; top:50%;margin-top:-125px;margin-left:-175px;width:350px;height:250px; }
</style>

然后是html

<div id="goog">