<img id="float" style="position:absolute" src="http://img.baidu.com/img/logo-zhidao.gif" />
<script>
var xPos = 0, yPos = 0, step = 1, yon = 0, xon = 0;
var img = document.getElementById("float");
function changePos() {
var width = document.body.clientWidth;
var height = document.body.clientHeight;
var Hoffset = img.offsetHeight;
var Woffset = img.offsetWidth;
img.style.left = xPos + document.body.scrollLeft;
img.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
} else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
} else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
setTimeout('changePos()', 30);
}
window.onload = changePos;
</script>
JavaScript-浮动广告
最新推荐文章于 2019-01-10 16:53:07 发布