我认为简单地创建一个位于页面中心的 div 和 AD 的内容要容易得多。
在这里,我还添加了一个 div,它将使整个页面褪色,除了 AD。
HTML:
<body onload="showAD();"> //This will show the AD as soon as the page loads
<div id="fade"> //The fading out of the page div
<div id="AD"> //This div is for your AD
//GOOGLE ADSENSE CODE
</div>
<br>
<button onClick="closeAD();">Close</button> //A button to close the AD
</div>
CSS:
#fade{
width: 100%:
height: 100%;
background: black;
opacity: 0.7;
text-align: center;
display: none;
}
#AD{
width: #whatever suits you#;
height: #whatever suits you#;
margin-top: 100px;
margin-right: auto;
margin-left: auto;
display: none;
}
Javascript:
function displayAD(){
document.getElementById("fade").style.display = block;
document.getElementById("AD").style.display = block;
}
function closeAD(){
document.getElementById("fade").style.display = none;
document.getElementById("AD").style.display = none;
}