body {
background-color: #FFF;
}
#annoyingAdvert {
position: absolute;
z-index: 2;
display: none;
width: 100px;
background-color: #FFC;
padding: 10px;
margin: 10px;
border: 5px solid yellow;
}
#closeBox {
position: absolute;
color: red;
font-size: 1.5em;
top: 0;
right: 0;
}
window.addEventListener("load",initAdvert,false);
function initAdvert() {
var adBox = "annoyingAdvert";
document.getElementById(adBox).style.display = "block";
document.getElementById("closeBox").addEventListener(
"click",
function() {
document.getElementById(adBox).style.display = "none";
},
false
);
}
function initAdvert() {
var adBox = "annoyingAdvert";
document.getElementById(adBox).style.display = "block";
document.getElementById(adBox).addEventListener("mouseover",slide,false);
document.getElementById("closeBox").addEventListener(
"click",
function() {
document.getElementById(adBox).style.display = "none";
},
false
);
}
function slide() {
var adBox = "annoyingAdvert";
if (nextPos(adBox) <= (document.body.clientWidth-150)) {
document.getElementById(adBox).style.left = nextPos(adBox) + "px";
setTimeout(slide,100);
}
function nextPos(elem) {
return document.getElementById(elem).offsetLeft+1;
}
}